jodd.util
Class Mutex

java.lang.Object
  extended by jodd.util.Mutex

public class Mutex
extends java.lang.Object

Provides simple mutual exclusion.

Interesting, the previous implementation based on Leslie Lamport's "Fast Mutal Exclusion" algorithm was not working, probably due wrong implementation.

Object (i.e. resource) that uses Mutex must be accessed only between lock() and unlock().


Constructor Summary
Mutex()
           
 
Method Summary
 void lock()
          Blocks execution and acquires a lock.
 boolean tryLock()
          Acquires a lock.
 void unlock()
          Releases a lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mutex

public Mutex()
Method Detail

lock

public void lock()
Blocks execution and acquires a lock. If already inside of critical block, it simply returns.


tryLock

public boolean tryLock()
Acquires a lock. If lock already acquired, returns false,


unlock

public void unlock()
Releases a lock.



Copyright ©2008 Jodd Team