Package org.daisy.dotify.common.io
Class InterProcessLock
- java.lang.Object
-
- org.daisy.dotify.common.io.InterProcessLock
-
public final class InterProcessLock extends Object
Provides an inter-process locking signal that can be used to negotiate access across JVMs. Whoever holds the lock has it until it's released by the owner. A lock should therefore be released as soon as the lock is no longer needed. In most cases, the following pattern should be used:InterProcessLock lock = ...; lock.lock(); try { // do work } finally { lock.unlock(); }
Locks remaining when the JVM exits will be released automatically.
-
-
Constructor Summary
Constructors Constructor Description InterProcessLock(File file)
Creates a new lock using the specified file.InterProcessLock(String id)
Creates a new lock with the specified id.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
lock()
Acquire the lock.void
unlock()
Releases a previously acquired lock.
-
-
-
Method Detail
-
lock
public boolean lock() throws LockException
Acquire the lock.- Returns:
- returns true if a lock was acquired, false otherwise
- Throws:
LockException
- if an error occurs when acquiring the lock
-
unlock
public void unlock()
Releases a previously acquired lock.
-
-