com.antiaction.critical
Class Multex
java.lang.Object
|
+--com.antiaction.critical.Multex
- public class Multex
- extends java.lang.Object
Basic counter semaphore, allows for controlled multithreaded access to data.
Losely based on a mutex implementation by Scott Oaks & Henry Wong.
Java Threads ISBN 1-56592-418-5.
This allows for the management of resources. Several threads can be admitted
access to the lock at the same time. For each released resource one can be
obtained.
This should be a very robust implementation.
In depth coverage of the subject can be found in the afore mentioned book.
- Version:
- 1.00
- Author:
- Nicholas Clarke
Constructor Summary |
Multex()
Initialize closed multex semaphore. |
Multex(int cnt)
Initialize multex semaphore with specified initial open slots. |
Method Summary |
boolean |
attemptSemaphore()
Attempt to obtain a free resource, returns either way. |
void |
obtainSemaphore()
This call returns when the current thread has obtained a free resource. |
void |
releaseSemaphore()
Release a resource, increases the amount of open slots. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Multex
public Multex()
- Initialize closed multex semaphore.
- See Also:
Multex(int)
Multex
public Multex(int cnt)
- Initialize multex semaphore with specified initial open slots.
- Parameters:
cnt
- initial open slots.- Throws:
java.lang.IllegalArgumentException
- in case a negative argument is passed.
obtainSemaphore
public void obtainSemaphore()
- This call returns when the current thread has obtained a free resource.
- See Also:
attemptSemaphore()
,
releaseSemaphore()
attemptSemaphore
public boolean attemptSemaphore()
- Attempt to obtain a free resource, returns either way.
- Returns:
- boolean indicating whether the attempt was successful or not.
- See Also:
obtainSemaphore()
releaseSemaphore
public void releaseSemaphore()
- Release a resource, increases the amount of open slots.
- See Also:
obtainSemaphore()