EDU.oswego.cs.dl.util.concurrent

Class ReentrantLock

Implemented Interfaces:
Sync

public class ReentrantLock
extends Object
implements Sync

A lock with the same semantics as builtin Java synchronized locks: Once a thread has a lock, it can re-obtain it any number of times without blocking. The lock is made available to other threads when as many releases as acquires have occurred.

[ Introduction to this package. ]

Field Summary

protected long
holds_
protected Thread
owner_

Fields inherited from interface EDU.oswego.cs.dl.util.concurrent.Sync

ONE_CENTURY, ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_SECOND, ONE_WEEK, ONE_YEAR

Method Summary

void
acquire()
boolean
attempt(long msecs)
long
holds()
Return the number of unreleased acquires performed by the current thread.
void
release()
Release the lock.
void
release(long n)
Release the lock N times.

Field Details

holds_

protected long holds_

owner_

protected Thread owner_

Method Details

acquire

public void acquire()
            throws InterruptedException
Specified by:
acquire in interface Sync

attempt

public boolean attempt(long msecs)
            throws InterruptedException
Specified by:
attempt in interface Sync

holds

public long holds()
Return the number of unreleased acquires performed by the current thread. Returns zero if current thread does not hold lock.

release

public void release()
Release the lock.
Specified by:
release in interface Sync

release

public void release(long n)
Release the lock N times. release(n) is equivalent in effect to:
   for (int i = 0; i <32n; ++i) release();