Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Java FileChannel.tryLock work on Mac OS X?

Tags:

java

macos

I have the code that similar to below. This code works fine on Windows and Linux but on Mac 10.5 and 10.6 gives java.io.Exception opertaion not supported.

Many thanks for any help in this regard.

try
{
  File file = new File("FILELOCK3");
  FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
  FileLock lock = null;
  try
  {
    lock = channel.tryLock();
  } catch (OverlappingFileLockException e)
  {
    lock.release();
    channel.close();
    System.exit(0);
  }
} catch (Exception e)
{
}
like image 928
Anil Avatar asked Oct 15 '22 01:10

Anil


1 Answers

From another source I get the impression that the error depends on the underlying file system:

Apple has not implemented file locking feature on a few selected file systems.

... and the referenced message was posted in May 2005.

like image 83
Andreas Dolk Avatar answered Oct 16 '22 15:10

Andreas Dolk