Java file locking on a network

前端 未结 4 1405
执念已碎
执念已碎 2021-01-17 12:01

This is perhaps similar to previous posts, but I want to be specific about the use of locking on a network, rather than locally. I want to write a file to a shared location,

4条回答
  •  借酒劲吻你
    2021-01-17 12:29

    This can't be reliably done on a network file system. As long as your application is the only application that accesses the file, it's best to implement some kind of cooperative locking process (perhaps writing a lock file to the network filesystem when you open the file). The reason that is not recommended, however, is that if your process crashes or the network goes down or any other number of issues happen, your application gets into a nasty, dirty state.

提交回复
热议问题