public interface LockBox<T> extends Box<T>
modify(Function)
happens within a synchronized block.
Using the transactOn(LockBox...)
method, you can obtain a lock
on multiple boxes in a way which is guaranteed to be free
of deadlock, so long as no one is getting a lock except through
modify(Function)
and transactOn(LockBox...)
.Modifier and Type | Method and Description |
---|---|
Object |
lock()
The lock which is used by this LockBox's
method . |
default <R> LockBox<R> |
map(Converter<T,R> converter)
Maps this LockBox to a new value which will have the
same lock as the original lock, since there's still
only one piece of state.
|
default T |
modify(Function<? super T,? extends T> mutator) |
static <T> LockBox<T> |
of(T value)
Creates a `LockBox` containing the given value, which uses itself as the lock.
|
static <T> LockBox<T> |
of(T value,
Object lock)
Creates a `LockBox` containing the given value, and using the given object as the lock.
|
static OrderedLock |
transactOn(LockBox... locks)
Creates an OrderedLock which allows running transactions on the given list of LockBoxes.
|
accept, from, ofVolatile, set
Object lock()
method
.
For a LockBox which holds state, the LockBox itself is used. For a mapped
LockBox, the underlying LockBox which actually holds the state is used.static <T> LockBox<T> of(T value)
static <T> LockBox<T> of(T value, Object lock)
default <R> LockBox<R> map(Converter<T,R> converter)
static OrderedLock transactOn(LockBox... locks)