File locking supported on all platforms?
Alan Bateman
Alan.Bateman at oracle.com
Tue Jul 14 09:31:42 UTC 2020
On 11/07/2020 15:13, Jonas Konrad wrote:
> I asked around and apparently fcntl locking can be idempotent in the
> same process at least for some fs, so locking twice in the same jvm
> may not error even on an fs that does support locks.
You should get an OverlappingFileLockException in that case. As a
reminder, the file locking API is intended for coordinating access with
other programs, it cannot be used to coordinate access to a file in the
same VM.
I see NFS is mentioned in the discussion. Yes, there can be issues in
NFS environments but if the lock daemon is not running on the remote NFS
server then I would expect the lock or tryLock methods to throw an
IOException "No locks available".
-Alan
More information about the nio-dev
mailing list