也许我在这里试图解释的内容没有任何意义,所以我想提前道歉。不管怎样,我会努力的。
我正在尝试从文件中读取,执行一些数据库操作并将内容移动到另一个文件。我想知道是否可以在 Java 中以原子方式执行所有这些操作,因此如果操作列表中出现任何问题,请回滚完整序列并返回起点。
提前感谢您的帮助。
最佳答案
看看Apache Commons Transaction .它具有以事务方式管理文件的能力。
安archived article详细说明了它在文件系统中的使用。
更新
请注意首页上的状态显示:
We have decided to move the project to dormant as we are convinced that the main advertised feature transactional file access can not be implemented reliably. We are convinced that no such implementation can be possible on top of an ordinary file system. Although there are other useful parts (as multi level locking including deadlock detection) the transactional file system is the main reason people use this library for. As it simply can not be made fully transactional, it does not work as advertised.
关于java - Java中文件操作的事务模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1311050/