I have an executable jar file which runs up to process files in a source directory. When starting to process a file, it is moved into a "processing" directory and finally moved into a completed directory.
This executable jar file is run up via a cron job
The issue I have encountered is that the executable jar runs are overlapping ie one run has not completed and a second run has started.
So there are 2 or maybe more executable jar running at the same time to process the files from the same source directory.
The idea is once a file is moved into a "processing" directory by the executable jar run, the file will not be visible to another executable jar run in the source directory.
However, it appears 2 or more of the executable jar runs are gaining the file in the source directory and start processing the file. The consequence is that only one executable jar run is able to complete the processing of the file and the others that thought had exclusive access to the file, are failing because the file is no longer there.
I am using the Files.move( srcPath, targetPath) provided in the Files class which is in the java.nio.file package to move files between directory.
Any suggestions as to how I could ensure only one executable jar run process a file at a time please ?
Thank you
Pete