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 t开发者_运维知识库he 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 ?
Avoid letting your regions overlap. You could also try to set the shared
flag to true
. But beware, that shared locks are os dependent. So they may not be available on all systems.
精彩评论