ini.trakem2.utils
Class Lock

java.lang.Object
  extended by ini.trakem2.utils.Lock

public class Lock
extends java.lang.Object

For thread synchronization. Both methods MUST ALWAYS be called from within a statement synchronizing on this object, such as:

final Lock lock = new Lock();
synchronized (lock) {
lock.lock();
try {
... (do whatever needs be synchronized on this lock) ...
} catch (Exception e) {
e.printStackTrace();
}
lock.unlock();
}
The advantage of using this class as opposed to a simple synchronized statement is that the lock may be set and unset from different synchronized blocks. For example:
final Lock lock = new Lock();
synchronized (lock) {
lock.lock();
// Do something
}
// Exit synchronized block, wait for other events to happen

// ...
// Enter again and unlock:
synchronized (lock) {
try {
... (do whatever needs be synchronized on this lock) ...
} catch (Exception e) {
e.printStackTrace();
}
lock.unlock();
}


Field Summary
protected  boolean debug
           
protected static boolean debug_all
           
protected  boolean locked
           
 
Constructor Summary
Lock()
           
 
Method Summary
 void debug()
           
static void debugAll()
           
 void lock()
           
 void unlock()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

locked

protected boolean locked

debug

protected boolean debug

debug_all

protected static boolean debug_all
Constructor Detail

Lock

public Lock()
Method Detail

lock

public final void lock()

unlock

public final void unlock()

debug

public final void debug()

debugAll

public static final void debugAll()