I have file locking and unlocking methods as follows,
Lock method,
fileLock = fileChannel.tryLock();
if (fileLock != null)
System.out.println("File is locked");
unlock method,
fileLock.release();
Now, this two methods are accessed by two concurrent processes. Now, if one processes crashes, before unlocking, another process can’t access the file until JVM is closed. Can anybody help me, is it possible (and how) to specify some time limit for locking the file.
Use singleton pattern. Then only one thread will access to your file.