This discussion is archived
1 Reply Latest reply: May 15, 2012 5:00 PM by EJP RSS

NFS v4 File Locking and nio

886218 Newbie
Currently Being Moderated
I am seeking to lock files in NFS mounted directories across mutlple JVMs on Linux.

I understand that java.nio.channels.FileChannel has a lock method
and that NFSv4 has a capability to lock that is more than was possible in NFSv3,
but does nio call this NFSv4 locking,
or does this depend on the Operating System and on whose Java implementation I am using?

Or is there another way to accomplish this?

I sometimes see discussion of a C API into NFS. Is calling C from Java the best way to deal with this?
Would I call fcntl? or something else?

Does the flock command-line intended for shell scripts work on NFS and
would it do the right thing if I call that from Java?

Thanks,

Mary-Anne
  • 1. Re: NFS v4 File Locking and nio
    EJP Guru
    Currently Being Moderated
    but does nio call this NFSv4 locking,
    or does this depend on the Operating System and on whose Java implementation I am using?
    It depends on the operating system. As far as I know NIO just calls flock(). What flock() does is up to the OS.
    I sometimes see discussion of a C API into NFS. Is calling C from Java the best way to deal with this?
    No.
    Would I call fcntl? or something else?
    flock().

    However I would caution you against using NFS locking at all, or indeed against writing applications that write to remote file systems. It is notoriously problematic. NFS locking is particularly so unless they have improved it considerably.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points