com.objectwave.utility
Class FileLock

java.lang.Object
  |
  +--com.objectwave.utility.FileLock

public class FileLock
extends java.lang.Object

Write an int to the head of a RandomAccessFile to mark it as locked.

Version:
1.2
Author:
Dave Hoag

Constructor Summary
FileLock()
           
 
Method Summary
static void getLock(java.io.RandomAccessFile file)
          Lock the provided file by setting the first int of the file to be a random number.
static void main(java.lang.String[] args)
          Both an example and a utility to manually release the lock.
static void releaseLock(java.io.RandomAccessFile file)
          Mark the initial int of a RandomAccessFile as a zero.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileLock

public FileLock()
Method Detail

main

public static void main(java.lang.String[] args)
Both an example and a utility to manually release the lock.


releaseLock

public static void releaseLock(java.io.RandomAccessFile file)
                        throws java.io.IOException
Mark the initial int of a RandomAccessFile as a zero. Effectively releasing the lock on the file.

java.io.IOException

getLock

public static void getLock(java.io.RandomAccessFile file)
                    throws java.io.IOException
Lock the provided file by setting the first int of the file to be a random number. Warning: The first int value will be set to a Random Number! Make sure this is ok. To prevent 'dead lock' always be sure to release a lock once it is obtained.

Parameters:
file - java.io.RandomAccessFile The file to be locked.
java.io.IOException