posix
Class LockFile

java.lang.Object
  extended by posix.LockFile

public class LockFile
extends Object

A simple unix style lock file. The first process to append its process id owns the lock. The lock is stale if the process id no longer exists. There is a race condition when removing stale locks.


Constructor Summary
LockFile(String name)
          Create a unix style lockfile.
 
Method Summary
 void delete()
          Remove the lockfile.
 void finalize()
          Remove the lockfile when garbage collected.
static void main(String[] argv)
          Exercise LockFile.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LockFile

public LockFile(String name)
         throws IOException
Create a unix style lockfile.

Parameters:
name - the unix path name of the lockfile
Throws:
IOException - if the lockfile is already owned or cannot be created
Method Detail

finalize

public void finalize()
Remove the lockfile when garbage collected.

Overrides:
finalize in class Object

delete

public void delete()
Remove the lockfile.


main

public static void main(String[] argv)
                 throws IOException
Exercise LockFile. Create one or more lock files from command line, print an error if they cannot all be locked at once, and remove them when user presses enter.

Throws:
IOException