Exclusive file lock

Discussion in 'Java' started by Bruintje Beer, Dec 21, 2007.

  1. Hi,

    I was wondering if there is a way to open a data file in exclusive mode not
    using the nio package. The reason for not using the nio package is not
    relevant I am just interrested in some kind of solution.

    John
    Bruintje Beer, Dec 21, 2007
    #1
    1. Advertising

  2. On Dec 21, 6:58 pm, "Bruintje Beer" <> wrote:
    > I was wondering if there is a way to open a data file in exclusive mode not
    > using the nio package. The reason for not using the nio package is not
    > relevant


    So you thing we are not worthy to know some background. But we should
    be glad to be at your service.

    Hint: Hire a consultant if you need to have someone you can push
    around.
    Hunter Gratzner, Dec 21, 2007
    #2
    1. Advertising

  3. Bruintje Beer

    Daniel Pitts Guest

    Bruintje Beer wrote:
    > Hi,
    >
    > I was wondering if there is a way to open a data file in exclusive mode not
    > using the nio package. The reason for not using the nio package is not
    > relevant I am just interrested in some kind of solution.
    >
    > John
    >
    >

    Exclusive file locks are often OS specific, and as such difficult to
    have a OS neutral implementation.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
    Daniel Pitts, Dec 21, 2007
    #3
  4. Bruintje Beer

    Roedy Green Guest

    On Fri, 21 Dec 2007 18:58:17 +0100, "Bruintje Beer" <>
    wrote, quoted or indirectly quoted someone who said :

    >I was wondering if there is a way to open a data file in exclusive mode not
    >using the nio package. The reason for not using the nio package is not
    >relevant I am just interrested in some kind of solution


    Only some half-assed solutions.

    see http://mindprod.com/jgloss/lockedfiles.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Dec 21, 2007
    #4
  5. Bruintje Beer

    Arne Vajhøj Guest

    Bruintje Beer wrote:
    > I was wondering if there is a way to open a data file in exclusive mode not
    > using the nio package. The reason for not using the nio package is not
    > relevant I am just interrested in some kind of solution.


    Write some C code and call it via JNI.

    Arne
    Arne Vajhøj, Dec 21, 2007
    #5
  6. Bruintje Beer

    Lew Guest

    Bruintje Beer wrote:
    >> I was wondering if there is a way to open a data file in exclusive
    >> mode not using the nio package. The reason for not using the nio
    >> package is not relevant I am just interrested in some kind of solution.


    How come you don't want to use NIO?

    Arne Vajhøj wrote:
    > Write some C code and call it via JNI.


    Assuming an OS for which it's possible to take out such a lock on a file.

    --
    Lew
    Lew, Dec 22, 2007
    #6
  7. Bruintje Beer

    EJP Guest

    > The reason for not using the nio package is not
    > relevant


    Your reason for not using the only package that provides a solution is
    *extremely* relevant.

    You only have to use NIO for the lock, not for the I/O. Start with a
    FileInputStream or RandomAccessFile, get the FileChannel from that, and
    lock the file.
    EJP, Dec 22, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven D'Aprano
    Replies:
    3
    Views:
    1,804
    Jeffrey Straszheim
    Dec 6, 2008
  2. Eugene Perederey

    Setting an exclusive lock on a file

    Eugene Perederey, Mar 29, 2009, in forum: Python
    Replies:
    2
    Views:
    264
    Diez B. Roggisch
    Mar 29, 2009
  3. Sea&Gull

    Exclusive lock of a file

    Sea&Gull, Jan 11, 2005, in forum: Ruby
    Replies:
    2
    Views:
    121
    Bill Atkins
    Jan 11, 2005
  4. Replies:
    0
    Views:
    80
  5. lokesh mavale
    Replies:
    1
    Views:
    66
Loading...

Share This Page