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
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!