com.github.libxjava.concurrent
Class ReentrantLock

java.lang.Object
  extended by com.github.libxjava.concurrent.ReentrantLock

public final class ReentrantLock
extends Object

Implementation of an "unfair" reentrant lock.

Version:
libxjava-cldc - 0.3
Author:
Marcel Patzlaff

Nested Class Summary
 class ReentrantLock.Condition
           
 
Constructor Summary
ReentrantLock()
           
 
Method Summary
protected  boolean doAcquire(int count)
           
protected  int doReleaseFully()
           
 int getCount()
          Returns the state of the internal acquisition counter.
 boolean isOwner()
          Checks whether the current thread is the owner of this lock.
 void lock()
          Blocks until this lock becomes available.
 void lockInterruptibly()
          Blocks until this lock becomes available.
 ReentrantLock.Condition newCondition()
           
 boolean tryLock()
          Tries to obtain the ownership of this lock and returns immediately.
 void unlock()
          Decrements the internal acquisition counter for this lock.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReentrantLock

public ReentrantLock()
Method Detail

lock

public void lock()
Blocks until this lock becomes available. A call to this method is not interruptible!

See Also:
lockInterruptibly()

lockInterruptibly

public void lockInterruptibly()
                       throws InterruptedException
Blocks until this lock becomes available. If the current thread is already the owner of this lock, internal acquisition counter is incremented.

Ensure that you release this lock as often as you acquired it!

If this thread is interrupted an InterruptedException will be thrown.

Throws:
InterruptedException

tryLock

public boolean tryLock()
Tries to obtain the ownership of this lock and returns immediately.

Returns:
true if acquisition was successful and false otherwise.

unlock

public void unlock()
            throws IllegalMonitorStateException
Decrements the internal acquisition counter for this lock. If the counter is zero afterwards, this lock is released. If the current thread is not owner of this lock an IllegalMonitorStateException will be thrown.

Throws:
IllegalMonitorStateException

isOwner

public boolean isOwner()
Checks whether the current thread is the owner of this lock.


getCount

public int getCount()
Returns the state of the internal acquisition counter.


newCondition

public ReentrantLock.Condition newCondition()

doReleaseFully

protected int doReleaseFully()

doAcquire

protected boolean doAcquire(int count)


Copyright © 2011 Marcel Patzlaff. All Rights Reserved.