|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Synchronizer
Interface for synchronizing arbitrary blocks of code within a JVM process.
These blocks of code must be expressed either as Runnable
s, or as Callable
s.
Runnable
s and Callable
s running in exclusive mode always waits for all other concurrent-mode blocks to finish,
then runs exclusively, queuing up all other blocks until it has finished.
Usage example:public Entity find(final Specification spec) { return getSynchronizer().runConcurrently(new Callable<Entity>() { public Entity call() { // do find... } }); } public void persist() { getSynchronizer().runExclusively(new Callable<Void>() { public Void call() { // do persist... return null; } }); }
Nested Class Summary | |
---|---|
static class |
Synchronizer.MODE
|
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. |
Method Detail |
---|
<R extends java.lang.Runnable> void runConcurrently(R runnable)
Runnable
in a concurrent manner.
runnable
- the runnable to invoke concurrently, managed by this class<T,C extends java.util.concurrent.Callable<T>> T callConcurrently(C callable)
Callable
in a concurrent manner.
callable
- the callable to invoke concurrently, managed by this class
Callable
's return value, or null
if no return value<R extends java.lang.Runnable> void runExclusively(R runnable)
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.
runnable
- the runnable to invoke exclusively, managed by this class<T,C extends java.util.concurrent.Callable<T>> T callExclusively(C callable)
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.
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 |