K
- key for the lockspublic class LockPool<K> extends Object
Constructor and Description |
---|
LockPool(java.util.function.Function<? super K,? extends ReentrantReadWriteLock> defaultLoader,
int initialSize,
int lowWatermark,
int highWatermark,
int concurrencyLevel)
Constructor for a lock pool.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(K key)
Returns whether the pool contains a particular key.
|
LockResource |
get(K key,
LockMode mode)
Locks the specified key in the specified mode.
|
Map<K,ReentrantReadWriteLock> |
getEntryMap() |
ReentrantReadWriteLock |
getRawReadWriteLock(K key)
Get the raw readwrite lock from the pool.
|
int |
size() |
Optional<LockResource> |
tryGet(K key,
LockMode mode)
Attempts to take a lock on the given key.
|
public LockPool(java.util.function.Function<? super K,? extends ReentrantReadWriteLock> defaultLoader, int initialSize, int lowWatermark, int highWatermark, int concurrencyLevel)
defaultLoader
- specify a function to generate a value based on a keyinitialSize
- initial size of the poollowWatermark
- low watermark of the pool sizehighWatermark
- high watermark of the pool sizeconcurrencyLevel
- concurrency level of the poolpublic LockResource get(K key, LockMode mode)
key
- the key to lockmode
- the mode to lock inpublic Optional<LockResource> tryGet(K key, LockMode mode)
key
- the key to lockmode
- lockMode to acquirepublic ReentrantReadWriteLock getRawReadWriteLock(K key)
key
- key to look up the valuepublic boolean containsKey(K key)
key
- the key to look up in the poolpublic int size()
public Map<K,ReentrantReadWriteLock> getEntryMap()
Copyright © 2023. All Rights Reserved.