Package de.xima.fc.common.concurrent
Class StripedLock
- java.lang.Object
-
- de.xima.fc.common.concurrent.StripedLock
-
- All Implemented Interfaces:
Serializable
public final class StripedLock extends Object implements Serializable
Similar to Guava's Striped, but with a few additions:Serializable,AutoCloseablesupport, and a method to lock all stripes.- Since:
- 8.3.0
- Author:
- XIMA MEDIA GmbH
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StripedLocklazyWeakStripedLock(int stripes)Creates a new striped lock with the given number of stripes.QuietAutoCloseablelockAll()Locks access to all stripes.QuietAutoCloseablelockMultiple(Iterable<?> stripes)Locks access to the given individual stripes.QuietAutoCloseablelockMultiple(Object... stripes)Locks access to the given individual stripes.QuietAutoCloseablelockSingle(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 Detail
-
lockAll
public QuietAutoCloseable 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
public QuietAutoCloseable lockMultiple(Object... stripes)
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
public QuietAutoCloseable lockMultiple(Iterable<?> stripes)
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
public QuietAutoCloseable lockSingle(Object stripe)
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
public static StripedLock lazyWeakStripedLock(int stripes)
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
public static StripedLock stripedLock(int stripes)
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.
-
-