Synchronization with Java through File Locks

Short version: 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