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
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

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




Release 3.0
Class Mutex

  extended by

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


public Mutex()
Creates an instance of Mutex.

Method Detail


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.

monitor - Eclipse Progress Monitor. May be null.
timeout - Maximum wait time given in milliseconds.
true if the lock was obtained successfully.


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


public boolean isLocked()
Return this Mutex's lock status.

true if this mutex is currently acquired by a thread.


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.

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