Java file locking mechanism for file based process communication

后端 未结 2 2016
难免孤独
难免孤独 2021-01-15 04:56

I have two java process (JAR) one is writing to a text file on every 1 min and another is reading that file and call a web service to store data in database.

Is ther

2条回答
  •  野的像风
    2021-01-15 05:22

    The problem you will have here is that Java cannot open() with O_EXCL, as a result you cannot create a file atomically.

    Use a directory instead: creating a directory is an atomic operation. File's .mkdir() will return false if the directory cannot be created. rmdir() it when you're done.

    Of course, make sure that both of your processes have write access to the base directory!

提交回复
热议问题