So far one test case has failed. Upon investigation, found that the behaviour of FileChannel locking is different on the Mac. It seems that Mac JVM allows multiple threads within the same JVM to acquire exclusive locks on a file concurrently - whereas on Windows, we get an OverlappingFileLockException exception. It also seems that within the same thread, it is okay to acquire a lock more than once on the same file on Mac but not on Windows.
I was relying on the locking behaviour I saw on Windows, to allow simpledbm to detect multiple instances of simpledbm running concurrently against the same database.
Interestingly, the specification of locking behaviour seems contradictory:
File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine.But on the other hand:
The locks held on a particular file by a single Java virtual machine do not overlap. The overlaps
method may be used to test whether a candidate lock range overlaps an existing lock.
Which is right?
No comments:
Post a Comment