Problem with FileLock



Hi experts,

We need to update a file (on a file server) from many different
machines. To synchromize the updates I am using FileLock.

Everything works as advertised (ie if a machine gets the lock,
it writes to the file while the other machines wait, everything is
written in the proper order). The same test, using Linux machines,
fails: the file is clobbered (meaning one update gets on top of
another). No Exceptions are thrown; in fact the debug statements
indicate that all the machines are acquiring the exclusive lock)

Anyone can shed light? Here is the critical method with some
debug statements:

public void write (String s) throws Exception {
ByteBuffer bb = stringToByteBuffer(s);

//lock the file and wait till we can
FileChannel channel = fos.getChannel();
FileLock lock = null;
try {
while ((lock = channel.tryLock()) == null) {
System.out.println (Utils.getHostname() + " Failed lock...wait");
Thread.sleep(100);
}

System.out.println (Utils.getHostname() + " Locked:" + lock);
System.out.println (Utils.getHostname() + " Lock type is "+
((lock.isShared())?"shared":"exclusive"));

System.out.println (Utils.getHostname() + " Is lock valid: " +
lock.isValid());

//write the title first if noone's done it
//and they asked for one
if (channel.size() <= 0 && bbTitle != null)
channel.write (bbTitle);
channel.write(bb);

} catch (Exception e) {
throw (e);
} finally {
if (lock != null) {
System.out.println (Utils.getHostname() + " Releasing lock");
lock.release();
}
}

}

.



Relevant Pages

  • Re: Problem with FileLock
    ... To synchromize the updates I am using FileLock. ... Everything works as advertised (ie if a machine gets the lock, ... writes to the file while the other machines wait, ... process that does so on behalf of the other (client) processes, ...
    (comp.lang.java.programmer)
  • Re: automatic login and screen lock on boot and logon scripts
    ... > login and then lock the screen, I run a clean install of win2k, no ... machines dont have tcp/ip stack ... > then automatically login but have the screen locked. ... user32.dll,LockWorkStation" in a batch file. ...
    (microsoft.public.win2000.general)
  • Is there some sort of portable Copy Protection??
    ... There is a lot of software out there that can lock a program to a particular machine, but that may be too severe in my case. ... I need to serialize it and encrypt the .exe file so the protection I do implement can't be circumvented. ... I could have a web server that the program contacts once a month or so which could invalidate the license if it could detect if the software was being run by an unlicensed user, but how would it distinguish beteen a valid user running the software on 10 of his machines, or 10 different users running the software? ... Or should I lock it to the machine and if the user want's to run it on more machines, offer to extend the license to 2 or 3 machines? ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Is there some sort of portable Copy Protection??
    ... is a lot of software out there that can lock a program to a particular ... invalidate the license if it could detect if the ... Is it possible to get a hardware id from the USB ... machine and if the user want's to run it on more machines, ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: TSCs are a no-no on i386
    ... machines to *occasionally* run code designed for the wrong architecture. ... architectural constraints and processors instructions sets. ... When a 486 executes "LOCK; CMPXCHG", it locks the bus during the whole cmpxchg ... will know nothing about such a lock emulation. ...
    (Linux-Kernel)