Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

RSE
Release 3.0

org.eclipse.rse.services.clientserver
Class SystemReentrantMutex

java.lang.Object
  extended by 
org.eclipse.rse.services.clientserver.SystemReentrantMutex

public class SystemReentrantMutex
extends Object

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; }

Since:
3.0

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

LOCK_STATUS_NOLOCK

public static final int LOCK_STATUS_NOLOCK
See Also:
Constant Field Values

LOCK_STATUS_AQUIRED

public static final int LOCK_STATUS_AQUIRED
See Also:
Constant Field Values

LOCK_STATUS_BORROWED

public static final int LOCK_STATUS_BORROWED
See Also:
Constant Field Values
Constructor Detail

SystemReentrantMutex

public SystemReentrantMutex()
Creates an instance of SystemMutex.

Method Detail

waitForLock

public int waitForLock(
ISystemOperationMonitor 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 - SystemOperationMonitor. May be null.
timeout - Maximum wait time given in milliseconds.
Returns:
LOCK_STATUS_AQUIRED if the lock was acquired successfully. LOCK_STATUS_BORROWED if the lock was borrowed. LOCK_STATUS_NOLOCK if otherwise.

release

public void release()
Release this mutex's lock. May only be called by the same thread that originally acquired the SystemMutex.


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(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.0

Copyright (c) IBM Corporation and others 2000, 2008. All Rights Reserved.

 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire