I am trying to use
FileLock lock(long position, long size,boolean shared)
in FileChannel
object As per the javadoc it can throw OverlappingFileLockException
. When I create a test program with 2 threads lock method seems to be waiting to acquire the lock (both exclusive and non exclusive) But when the number threads increases in the acutal scenario over lapping file lock exception is thrown and processing slows down due the block at File lock table.
What is the best way to acquire lock avoiding the OverlappingFileLockException ?