public final class ParcelLock
extends java.lang.Object
synchronize(HashId, Function)
and execute your code in a callable argument.Constructor | Description |
---|---|
ParcelLock() |
Modifier and Type | Method | Description |
---|---|---|
int |
size() |
Niber of cached locks.
|
<T> T |
synchronize(HashId id,
java.util.function.Function<java.lang.Object,T> callable) |
Execute a callable acquiring a unique lock (mutex) for a given
HashId . |
public <T> T synchronize(HashId id, java.util.function.Function<java.lang.Object,T> callable) throws java.lang.Exception
HashId
. Locks is released upon callable
return.T
- typeid
- ot get a lock tocallable
- lamda to execute exclusively for the idjava.lang.Exception
- whatever callable throwspublic int size()
HashId
is
alive, so do not clone() and copy them, use shared instance (it is generally immutable). When the last instance
of this itemId will be garbage collected, the lock will be removed from the cache.