In Java What is the guaranteed way to get a FileLock from FileChannel while accessing a RandomAcces

Posted by narasimha.bhat on Stack Overflow See other posts from Stack Overflow or by narasimha.bhat
Published on 2010-05-20T14:18:01Z Indexed on 2010/05/20 14:20 UTC
Read the original article Hit count: 340

Filed under:
|
|
|
|

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 ?

© Stack Overflow or respective owner

Related posts about java

Related posts about nio