|
 |
|
|
org.eclipse.rse.services
Class Mutex
java.lang.Object
org.eclipse.rse.services.Mutex
-
public class Mutex
- extends
Object
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. |
Methods inherited from class java.lang.
Object
|
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
|
Mutex
public Mutex()
- Creates an instance of Mutex.
waitForLock
public boolean waitForLock(
IProgressMonitor monitor,
long timeout)
- Try to acquire the lock maintained by this mutex.
If the thread needs to wait before it can acquire the mutex, it
will wait in a first-come-first-serve fashion. In case a progress
monitor was given, it will be updated and checked for cancel every
second.
-
-
Parameters:
-
monitor - Eclipse Progress Monitor. May be null . -
timeout - Maximum wait time given in milliseconds.
-
Returns:
-
true if the lock was obtained successfully.
release
public void release()
- Release this mutex's lock.
May only be called by the same thread that originally acquired
the Mutex.
-
isLocked
public boolean isLocked()
- Return this Mutex's lock status.
-
-
Returns:
-
true if this mutex is currently acquired by a thread.
interruptAll
public void interruptAll()
- Interrupt all threads waiting for the Lock, causing their
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.
-
Copyright (c) IBM Corporation and others 2000, 2008. All Rights Reserved.
|
|
|