1 Reply Latest reply on May 16, 2012 12:00 AM by EJP

    NFS v4 File Locking and nio

    mgwmgw
      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
          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.