|
RSE Release 3.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.rse.services.clientserver.SystemReentrantMutex
public class SystemReentrantMutex
A reentrant Exclusion Lock for Threads that need to access a resource in a
serialized manner. If the request for the lock is running on the same thread
who is currently holding the lock, it will "borrow" the lock, and the call to
waitForLock() will go through. A SystemOperationMonitor is accepted in order
to support cancellation when waiting for the Mutex. This is a clone of
Mutex
with some modification to make sure the
sequential calls to waitForLock() method in the same thread will not be
blocked.
Usage Example:
private SystemReentrantMutex fooMutex = new SystemReentrantMutex();
boolean doFooSerialized()(ISystemOperationMonitor monitor) {
int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK;
mutexLockStatus = fooMutex.waitForLock(monitor, 1000);
if (mutexLockStatus != SystemReentrantMutex.LOCK_STATUS_NOLOCK) {
try {
return doFoo();
} finally {
//We only release the mutex if we acquire it, not borrowed it.
if (mutexLockStatus == SystemReentrantMutex.LOCK_STATUS_AQUIRED)
{
fooMutex.release();
}
}
}
return false;
}
Field Summary | |
---|---|
static int |
LOCK_STATUS_AQUIRED
|
static int |
LOCK_STATUS_BORROWED
|
static int |
LOCK_STATUS_NOLOCK
|
Constructor Summary | |
---|---|
SystemReentrantMutex()
Creates an instance of SystemMutex. |
Method Summary | |
---|---|
void |
interruptAll()
Interrupt all threads waiting for the Lock, causing their waitForLock(ISystemOperationMonitor, long) method to return
false . |
boolean |
isLocked()
Return this Mutex's lock status. |
void |
release()
Release this mutex's lock. |
int |
waitForLock(ISystemOperationMonitor 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 |
Field Detail |
---|
public static final int LOCK_STATUS_NOLOCK
public static final int LOCK_STATUS_AQUIRED
public static final int LOCK_STATUS_BORROWED
Constructor Detail |
---|
public SystemReentrantMutex()
Method Detail |
---|
public int waitForLock(ISystemOperationMonitor monitor, long timeout)
monitor
- SystemOperationMonitor. May be null
.timeout
- Maximum wait time given in milliseconds.
LOCK_STATUS_AQUIRED
if the lock was acquired successfully.
LOCK_STATUS_BORROWED
if the lock was borrowed.
LOCK_STATUS_NOLOCK
if otherwise.public void release()
public boolean isLocked()
true
if this mutex is currently acquired by a thread.public void interruptAll()
waitForLock(ISystemOperationMonitor, 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.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |