Posted on May 12th, 2006 by tpo
Synchronization from non-Java with Java through File Locks
Synchronization with Java through File Locks
use
lockf/fcntl and
not flock for synchronization through file locks
with Java. When one process uses flock and the other
lockf, then they will not be able to see each other's
locks.
Rant version:
Java praises itself as being truly portable. Since 1.4 it also has a platform-independent file locking mechanism that is visible accross process boundaries and is meant for synchronization with non-Java applications [1].
Although the manual talks lenghtily about platform issues [2] it stays completey silent on the fact, that if you want to synchronize with Java you must use the
lockf/fcntl mechanism in non-Java applications in order
to see Java's file locks and in order for Java to be able to see the
non-Java application's ones.
How not documenting the fact leads to portable applications, in spite of the fact that many [3] other [4] languages use
flock instead remains to be seen.
Tomas Pospisek
References
- [1] Sun's Java Tech Tips: Locking Files For Shared Access and Changing User Interface Attributes
- [2] Sun's FileLock documentation
- [3] Ruby's file locking implementation
- [4] Perl's file locking implementation

Services
Sources
About us