|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.allcolor.yahp.converter.CMutex
public final class CMutex
This is a simple mutex (Mutual Exclusion) class, which permits to synchronize Thread access to some parts of the code. Example usage : CMutex m = new CMutex(); private void mymethod() { m.acquire(); try { do something... } finally { m.release(); } }
Nested Class Summary | |
---|---|
private static class |
CMutex.CMutexComparator
This class is used to sort the mutex when acquiring multiple |
Field Summary | |
---|---|
private int |
acquire
number of time the owner has acquired this mutex |
private int |
id
id of the mutex, used for sorting |
private static java.lang.Object |
IDLOCK
used for serial access to the static id (sid) |
private java.lang.Object |
LOCK
used to implement the locking mechanism |
private java.lang.ref.WeakReference |
owner
owner of the mutex |
private static int |
sid
used to create unique id |
Constructor Summary | |
---|---|
CMutex()
Creates a new CMutex object. |
Method Summary | |
---|---|
void |
acquire()
Acquires this mutex |
void |
acquire(long timeout)
Acquires this mutex |
static void |
acquireMultiple(CMutex[] mutex)
Acquires an array of mutex |
static void |
acquireMultiple(long timeout,
CMutex[] mutex)
Acquires an array of mutex |
boolean |
isOwner()
return true if Thread.currentThread is the owner of the mutex. |
void |
release()
Releases the mutex |
static void |
releaseMultiple(CMutex[] mutex)
Releases an array of mutex previously acquired |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.Object IDLOCK
private static int sid
private int id
private final java.lang.Object LOCK
private java.lang.ref.WeakReference owner
private int acquire
Constructor Detail |
---|
public CMutex()
Method Detail |
---|
public final void acquire()
public final void acquire(long timeout) throws java.lang.RuntimeException
timeout
- maximum time to wait for acquiring
java.lang.RuntimeException
- if timeout is reached and no acquire was
possible.public final void release()
java.lang.IllegalMonitorStateException
- If currentThread is not the owner.public static final void acquireMultiple(long timeout, CMutex[] mutex) throws java.lang.RuntimeException
timeout
- maximum time to waitmutex
- the mutex array to acquire
java.lang.RuntimeException
- if timeout is reachedpublic static final void acquireMultiple(CMutex[] mutex)
mutex
- the mutex array to acquirepublic static final void releaseMultiple(CMutex[] mutex)
mutex
- the mutex array to releasepublic final boolean isOwner()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |