public class StripedLock
extends java.lang.Object
Currently this class only provides objects that should be synchronized on. Compared to
Lock
objects which have lock()
, tryLock()
,
and unlock()
functionality. This choice was primarily because of the way the internals
of threadly work.
Constructor and Description |
---|
StripedLock(int expectedConcurrencyLevel)
Constructs a new
StripedLock with a given expected concurrency level. |
Modifier and Type | Method and Description |
---|---|
int |
getExpectedConcurrencyLevel()
Getter for the expected concurrency level this class was constructed with.
|
java.lang.Object |
getLock(int hashCode)
Call to get a lock object for a given hash code.
|
java.lang.Object |
getLock(java.lang.Object key)
Call to get a lock object for a given key.
|
public StripedLock(int expectedConcurrencyLevel)
StripedLock
with a given expected concurrency level. The higher the
concurrency level, the less lock contention will exist, but more locks will have to be
synchronized on and more memory will be used to store the locks.expectedConcurrencyLevel
- expected level of parallelismpublic int getExpectedConcurrencyLevel()
public java.lang.Object getLock(java.lang.Object key)
key
- to use hashCode()
from to determine lockpublic java.lang.Object getLock(int hashCode)
hashCode
- to use to determine which lock to return