jodd.util
Class Mutex

java.lang.Object
  extended byjodd.util.Mutex

public class Mutex
extends java.lang.Object

Class that provides fast mutual exclusion using Leslie Lamport's "Fast Mutal Exclusion" algorithm. This class does not use the built-in synchronization monitor primitives of the Java language, thus allowing for proper synchronization across method calls. Object (i.e. resource) that uses Mutex must be accessed only between lock() and unlock().


Constructor Summary
Mutex()
          Constructor.
 
Method Summary
 boolean isLocked()
          Probe the mutex state.
 void lock()
          Aquire mutex.
 void unlock()
          Release an aquired mutex.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mutex

public Mutex()
Constructor.

Method Detail

lock

public void lock()
Aquire mutex. When this method returns, the calling thread have the mutex, and is can for all practical purposes be said to be within whatever critical region this mutex instance is supposed to protect. The method uses the calling thread's thread reference (obtained via Thread.currentThread()) to uniquely identify a thread.


unlock

public void unlock()
Release an aquired mutex. This particular implementation will allow both releases from non-owning threads, as well as multiple releases.


isLocked

public boolean isLocked()
Probe the mutex state. Note that this is inaccurate, and can only serve as an indication of whether the mutex is in use or not.

Returns:
true if the mutex is locked at the time of the probe, false otherwise.


Jodd v0.24.5 Javadoc