I have a program that locks a file like so, where lock
is the file:
FileChannel channel = new RandomAccessFile(lock,"rw").getChannel();
FileLock lock = channel.lock();
The main purpose is, using a secondary program, check to see if the program was killed. The secondary program's code looks like this:
boolean isNotLocked = false;
while (true){
while (isNotLocked){
lock.renameTo(lock);
}
//run the program again
}
It works the first time, and the program is run again, but after the program is run again, the secondary program throws a OverlappingFileLockException
and terminates. The main program is creating the lock, not the secondary one.