|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.domian.util.concurrent.locks.SemaphoreSynchronizer
public final class SemaphoreSynchronizer
A Synchronizer
implementation using two Semaphore
instances.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface net.sourceforge.domian.util.concurrent.locks.Synchronizer |
---|
Synchronizer.MODE |
Field Summary | |
---|---|
private java.util.concurrent.Semaphore |
concurrentAccessSemaphore
Semaphore managing permits and blocking queue for concurrent-mode blocks. |
private java.util.concurrent.Semaphore |
exclusiveAccessSemaphore
Semaphore managing one single permit and blocking queue for exclusive-mode blocks. |
private static boolean |
FAIR
|
private static java.util.concurrent.atomic.AtomicBoolean |
hasAcquiredExecutionPermitAtomicBoolean
|
private static java.lang.ThreadLocal<java.lang.Boolean> |
hasAcquiredExecutionPermitThreadLocal
Permits must only be acquired once per thread. |
private static org.slf4j.Logger |
log
|
private static int |
MAX_NUMBER_OF_CONCURRENT_PERMITS
|
private static boolean |
NON_FAIR
|
Constructor Summary | |
---|---|
SemaphoreSynchronizer()
|
Method Summary | ||
---|---|---|
|
callConcurrently(C callable)
Calls a Callable in a concurrent manner. |
|
|
callExclusively(C callable)
Calls a Callable in an exclusive manner. |
|
|
runConcurrently(R runnable)
Runs a Runnable in a concurrent manner. |
|
|
runExclusively(R runnable)
Runs a Runnable in an exclusive manner. |
|
private static void |
setThisThreadHasAcquiredExecutionPermitTo(java.lang.Boolean booleanValue)
|
|
private static java.lang.Boolean |
thisThreadHasAlreadyAcquiredExecutionPermit()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final org.slf4j.Logger log
private static final int MAX_NUMBER_OF_CONCURRENT_PERMITS
private static final boolean FAIR
private static final boolean NON_FAIR
private final java.util.concurrent.Semaphore concurrentAccessSemaphore
private final java.util.concurrent.Semaphore exclusiveAccessSemaphore
private static final java.util.concurrent.atomic.AtomicBoolean hasAcquiredExecutionPermitAtomicBoolean
private static final java.lang.ThreadLocal<java.lang.Boolean> hasAcquiredExecutionPermitThreadLocal
Constructor Detail |
---|
public SemaphoreSynchronizer()
Method Detail |
---|
private static java.lang.Boolean thisThreadHasAlreadyAcquiredExecutionPermit()
private static void setThisThreadHasAcquiredExecutionPermitTo(java.lang.Boolean booleanValue)
public <R extends java.lang.Runnable> void runConcurrently(R runnable)
Synchronizer
Runnable
in a concurrent manner.
runConcurrently
in interface Synchronizer
runnable
- the runnable to invoke concurrently, managed by this classpublic <T,C extends java.util.concurrent.Callable<T>> T callConcurrently(C callable)
Synchronizer
Callable
in a concurrent manner.
callConcurrently
in interface Synchronizer
callable
- the callable to invoke concurrently, managed by this class
Callable
's return value, or null
if no return valuepublic <R extends java.lang.Runnable> void runExclusively(R runnable)
Synchronizer
Runnable
in an exclusive manner.
Firstly, it will wait for all other exclusive Runnable
s and Callable
s to finish, if any.
Then it will wait for already running concurrent Runnable
s and Callable
s to finish, if any.
Finally it will run, queuing up all other Runnable
s and Callable
s managed by the same Synchronizer
instance.
When done, all queues are released.
runExclusively
in interface Synchronizer
runnable
- the runnable to invoke exclusively, managed by this classpublic <T,C extends java.util.concurrent.Callable<T>> T callExclusively(C callable)
Synchronizer
Callable
in an exclusive manner.
Firstly, it will wait for all other exclusive Runnable
s and Callable
s to finish, if any.
Then it will wait for already running concurrent Runnable
s and Callable
s to finish, if any.
Finally it will run, queuing up all other Runnable
s and Callable
s managed by the same Synchronizer
instance.
When done, all queues are released.
callExclusively
in interface Synchronizer
callable
- the callable to invoke exclusively, managed by this class
Callable
's return value, or null
if no return value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |