FIM.Synchronisation
Class Mutex
java.lang.Object
|
+--FIM.Synchronisation.Mutex
- public final class Mutex
- extends Object
A standard mutual exclusion as defined in books on operating systems. Used if only
one thread at any time may execaute a certain piece of code. At the beginning of the critical
section call lock
and at the end unlock
.
- Version:
- 1.0, 1.7.2000
- Author:
- Michael Sonntag
- See Also:
Thread
Constructor Summary |
Mutex()
|
Method Summary |
boolean |
lock()
Try to acquire the mutex. |
boolean |
lock(int millis)
Try to acquire the mutex for up to a maximum of the provided time in milliseconds. |
void |
unlock()
Releases the mutex. |
Methods inherited from class java.lang.Object |
,
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Mutex
public Mutex()
lock
public boolean lock(int millis)
throws InterruptedException
- Try to acquire the mutex for up to a maximum of the provided time in milliseconds.
- Parameters:
millis
- number of milliseconds to wait. Providing 0 will wait indefinitely- Returns:
- true if the mutex was acquired, false if the time ran out without success
- Throws:
- InterruptedException - if the wait for the mutex was interrupt
- See Also:
Thread
lock
public boolean lock()
throws InterruptedException
- Try to acquire the mutex. Will wait indefinitely till the mutex is acquired or it is
interrupt.
- Returns:
- true if the mutex was acquired, false if the time ran out without success
- Throws:
- InterruptedException - if the wait for the mutex was interrupted
- See Also:
Thread
unlock
public void unlock()
- Releases the mutex. May only be called by the thread possessing the mutex (else a
RuntimeException
will be thrown). If threads are waiting, one of them
is released and can acquire the mutex. Which of them is NOT defined!
Submit a bug
Copyright 2000 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.