I have a C++ program that locks files using POSIX advisory locks. That is, it uses the POSIX fcntl
system call for lock operations. I want a Java program to interoperate with that C++ program, so I want my Java program to also use POSIX advisory locks. File locking in Java should use the standard FileLock
class. But the API documentation is understandably vague on just how locking is implemented:
This file-locking API is intended to map directly to the native locking facility of the underlying operating system. Thus the locks held on a file should be visible to all programs that have access to the file, regardless of the language in which those programs are written.
If I am running a common implementation of Java (Oracles, Open JDK) on a POSIX operating system, or more specifically a GNU/Linux system, is it safe to assume that the Java FileLock
class uses POSIX advisory locks?
flock
system call. Which might or might not be implemented usingfcntl
. – Sorcimflock
does not support record-level locking. – Sorcimflock
is incompatible withfcntl
(andlockf
) on Linux. The two are essentially invisible to one another. So there is indeed a point to this question. – Nordin