How to atomically rename a file in Java, even if the dest file already exists?

前端 未结 8 2091
难免孤独
难免孤独 2020-12-09 07:55

I have a cluster of machines, each running a Java app.

These Java apps need to access a unique resource.txt file concurently.

I need to atomical

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 07:58

    As stated here, it looks like the Windows OS doesn't even support atomic file rename for older versions. It's very likely you have to use some manual locking mechanisms or some kind of transactions. For that, you might want to take a look into the apache commons transaction package.

提交回复
热议问题