org.knime.core.util
Class FileLocker

java.lang.Object
  extended by org.knime.core.util.FileLocker

public class FileLocker
extends Object

This class can be used to get a lock on the specified file. The lock can be aquired and released. If it is not explicitly released, it will be released as soon as the JVM is terminated.

Author:
Christoph Sieb, University of Konstanz

Constructor Summary
FileLocker(File lockFile)
          Creates a FileLocker on the given file.
 
Method Summary
 boolean lock()
          Tries to auquire the lock on the given File.
 void release()
          Releases a previously aquired lock on the specified file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileLocker

public FileLocker(File lockFile)
Creates a FileLocker on the given file. Creating the locker does not mean, that the file is also locked. For this, use the methods lock and release.

Parameters:
lockFile - the file for which to aquire and release locks
Method Detail

lock

public boolean lock()
             throws IOException
Tries to auquire the lock on the given File.

Returns:
true, if the lock could be aquired, false otherwise
Throws:
IOException - in case there is something wrong with the io actions

release

public void release()
Releases a previously aquired lock on the specified file. If there was no lock on the file, nothing happens.



Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.