public class ConcurrentBarrier extends Object
Runnable
object
(that returns no value), or a Invokable
object (which does return a value).Constructor and Description |
---|
ConcurrentBarrier() |
Modifier and Type | Method and Description |
---|---|
boolean |
tryWithWrite(Runnable runnable,
long timeout,
TimeUnit timeoutUnit)
Try to aquire the exclusive write lock and invoke the Runnable.
|
<T> T |
withRead(Invokable<T> invokable)
Invokes the object after acquiring the read lock (if necessary).
|
void |
withRead(Runnable runnable)
As with
withRead(Invokable) , creating an Invokable wrapper around the runnable object. |
<T> T |
withWrite(Invokable<T> invokable)
Acquires the exclusive write lock before invoking the Invokable.
|
void |
withWrite(Runnable runnable)
As with
withWrite(Invokable) , creating an Invokable wrapper around the runnable object. |
public ConcurrentBarrier()
public <T> T withRead(Invokable<T> invokable)
T
- invokable
- public void withRead(Runnable runnable)
withRead(Invokable)
, creating an Invokable
wrapper around the runnable object.public <T> T withWrite(Invokable<T> invokable)
Invokable
object should
be prepared for cases where the state has changed slightly, despite holding the read lock. This usually manifests
as race conditions where either a) some parallel unrelated bit of work has occured or b) duplicate work has
occured. The latter is only problematic if the operation is very expensive.T
- invokable
- public void withWrite(Runnable runnable)
withWrite(Invokable)
, creating an Invokable
wrapper around the runnable object.public boolean tryWithWrite(Runnable runnable, long timeout, TimeUnit timeoutUnit)
withWrite(Runnable)
and will return true. If the write lock is not
obtained within the timeout then the runnable is never invoked and the method will return false.runnable
- Runnable object to execute inside the write lock.timeout
- Time to wait for write lock.timeoutUnit
- Units of timeout.5.6.3 - Copyright © 2003-2021 The Apache Software Foundation.