Class StripedLock
java.lang.Object
de.xima.fc.common.concurrent.StripedLock
- All Implemented Interfaces:
Serializable
Similar to Guava's Striped, but with a few additions:
Serializable, AutoCloseable support, and a
method to lock all stripes.- Since:
- 8.3.0
- Author:
- XIMA MEDIA GmbH
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StripedLocklazyWeakStripedLock(int stripes) Creates a new striped lock with the given number of stripes.lockAll()Locks access to all stripes.lockMultiple(Iterable<?> stripes) Locks access to the given individual stripes.lockMultiple(Object... stripes) Locks access to the given individual stripes.lockSingle(Object stripe) Locks access to a single stripe.static StripedLockstripedLock(int stripes) Creates a new striped lock with the given number of stripes.intstripes()Gets the number of stripes.booleanweak()Gets whether weak lazy locks are used.
-
Method Details
-
lockAll
Locks access to all stripes. No other thread may execute when this lock is held.- Returns:
- A quiet auto-closeable that releases the lock when closed.
-
lockMultiple
Locks access to the given individual stripes. Multiple threads may execute with locks on different file stripes.- Parameters:
stripes- The stripes to lock.- Returns:
- A quiet auto-closeable that releases the lock when closed.
-
lockMultiple
Locks access to the given individual stripes. Multiple threads may execute with locks on different file stripes.- Parameters:
stripes- The stripes to lock.- Returns:
- A quiet auto-closeable that releases the lock when closed.
-
lockSingle
Locks access to a single stripe. Multiple threads may execute with a lock on different file keys.- Parameters:
stripe- The stripe to lock.- Returns:
- A quiet auto-closeable that releases the lock when closed.
-
stripes
public int stripes()Gets the number of stripes.- Returns:
- The number of stripes.
-
weak
public boolean weak()Gets whether weak lazy locks are used.- Returns:
- Whether weak lazy locks are used.
-
lazyWeakStripedLock
Creates a new striped lock with the given number of stripes. The locks are created lazily when required and are released when not referenced anymore.- Parameters:
stripes- The number of stripes.- Returns:
- The striped lock.
-
stripedLock
Creates a new striped lock with the given number of stripes. The locks are created eagerly and are not released at least until the striped lock is garbage collected.- Parameters:
stripes- The number of stripes.- Returns:
- The striped lock.
-