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

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

  3. Daniel Pitts

    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. Roedy Green

    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. Arne Vajhøj

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

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

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

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. Fuzzyman
    Replies:
    3
    Views:
    698
    Andrew MacIntyre
    Dec 5, 2003
  2. Steven D'Aprano
    Replies:
    3
    Views:
    2,082
    Jeffrey Straszheim
    Dec 6, 2008
  3. k3xji
    Replies:
    7
    Views:
    1,041
    Gabriel Genellina
    Dec 30, 2008
  4. Eugene Perederey

    Setting an exclusive lock on a file

    Eugene Perederey, Mar 29, 2009, in forum: Python
    Replies:
    2
    Views:
    354
    Diez B. Roggisch
    Mar 29, 2009
  5. nano2k

    Application.Lock()/UnLock() or lock(Application)

    nano2k, Jul 23, 2007, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    471
    nano2k
    Aug 9, 2007
  6. Sea&Gull

    Exclusive lock of a file

    Sea&Gull, Jan 11, 2005, in forum: Ruby
    Replies:
    2
    Views:
    220
    Bill Atkins
    Jan 11, 2005
  7. Replies:
    0
    Views:
    181
  8. lokesh mavale
    Replies:
    1
    Views:
    153
Loading...