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
Answertopia.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
Class Mutex


java.lang.Object
  extended by 
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.
 
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

Mutex

public Mutex()
Creates an instance of Mutex.

Method Detail

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.


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