|
RSE Release 3.2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.rse.services.Mutex
public class Mutex
A Mutual Exclusion Lock for Threads that need to access a resource
in a serialized manner. An Eclipse ProgressMonitor is accepted
in order to support cancellation when waiting for the Mutex.
Usage Example:
private Mutex fooMutex = new Mutex();
boolean doFooSerialized()(IProgressMonitor monitor) {
if (fooMutex.waitForLock(monitor, 1000)) {
try {
return doFoo();
} finally {
fooMutex.release();
}
}
return false;
}
The Mutex is not reentrant, so when a Thread has locked the
Mutex it must not try locking it again.
Constructor Summary | |
---|---|
Mutex()
Creates an instance of Mutex. |
Method Summary | |
---|---|
void |
interruptAll()
Interrupt all threads waiting for the Lock, causing their waitForLock(IProgressMonitor, long) method to return
false . |
boolean |
isLocked()
Return this Mutex's lock status. |
void |
release()
Release this mutex's lock. |
boolean |
waitForLock(IProgressMonitor monitor,
long timeout)
Try to acquire the lock maintained by this mutex. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Mutex()
Method Detail |
---|
public boolean waitForLock(IProgressMonitor monitor, long timeout)
monitor
- Eclipse Progress Monitor. May be null
.timeout
- Maximum wait time given in milliseconds.
true
if the lock was obtained successfully.public void release()
public boolean isLocked()
true
if this mutex is currently acquired by a thread.public void interruptAll()
waitForLock(IProgressMonitor, long)
method to return
false
.
This should be called if the resource that the Threads are
contending for, becomes unavailable for some other reason.
|
RSE Release 3.2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |