org.norther.tammi.acorn.util.concurrent
Class Mutex

java.lang.Object
  extended by org.norther.tammi.acorn.util.concurrent.Mutex
All Implemented Interfaces:
Serializable, Lock

public class Mutex
extends Object
implements Lock, Serializable

A non-reentrant mutual exclusion lock.

Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
Mutex()
           
 
Method Summary
 int getQueueLength()
          Gets the number of threads waiting to acquire this lock.
 boolean hasQueuedThreads()
          Queries whether any threads are waiting to acquire this lock.
 void lock()
           
 void lockInterruptibly()
           
 Condition newCondition()
           
 boolean tryLock()
           
 boolean tryLock(long timeout, TimeUnit unit)
           
 void unlock()
           
 
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()
Specified by:
lock in interface Lock

tryLock

public boolean tryLock()
Specified by:
tryLock in interface Lock

unlock

public void unlock()
Specified by:
unlock in interface Lock

newCondition

public Condition newCondition()
Specified by:
newCondition in interface Lock

lockInterruptibly

public void lockInterruptibly()
                       throws InterruptedException
Specified by:
lockInterruptibly in interface Lock
Throws:
InterruptedException

tryLock

public boolean tryLock(long timeout,
                       TimeUnit unit)
                throws InterruptedException
Specified by:
tryLock in interface Lock
Throws:
InterruptedException

hasQueuedThreads

public final boolean hasQueuedThreads()
Queries whether any threads are waiting to acquire this lock.

Note that because of cancellations, a true return does not guarantee that any other thread will ever acquire this lock.

Returns:
true if there may be other threads waiting to acquire this lock.

getQueueLength

public final int getQueueLength()
Gets the number of threads waiting to acquire this lock.

Note that the value is only an estimate because the number of threads may change dynamically while this method is executing.

Returns:
the estimated number of threads waiting for this lock


Copyright © 2004 The Norther Organization. All rights reserved.