Unable to lock files on Linux using java.nio.channels.FileLock

后端 未结 6 1162
花落未央
花落未央 2020-12-11 20:34

I was creating an application in Java for which I want only one instance running. For this purpose I created a file and got a lock while my application is running.

I

6条回答
  •  温柔的废话
    2020-12-11 21:00

    I used same sample as you and got same problem on Mac OS X. It seems that file lock does not prevent file deletion on POSIX systems . Your app wil still have some kind of handle to that file until you unlock it. So consider using lock file with PID in it's name( or inside file).

提交回复
热议问题