public final class DefaultLockRegistry extends java.lang.Object implements LockRegistry
LockRegistrywhich uses Masked Hashcode algorithm to obtain locks. When an instance of this class is created and array of
Lockobjects is created. The length of the array is based on the 'mask' parameter passed in the constructor. The default mask is 0xFF which will create and array consisting of 256
ReentrantLockinstances. When the
obtain(Object)method is called with the lockKey (e.g., Object) the index of the
Lockis determined by masking the object's hashCode (e.g.,
object.hashCode & mask) and the
|Constructor and Description|
Constructs a DefaultLockRegistry with the default mask 0xFF with 256 locks.
Constructs a DefaultLockRegistry with the supplied mask - the mask must have a value Math.pow(2, n) - 1 where n is 1 to 31, creating a hash of Math.pow(2, n) locks.
|Modifier and Type||Method and Description|
Obtains a lock by masking the lockKey's hashCode() with the mask and using the result as an index to the lock table.
public DefaultLockRegistry(int mask)
public java.util.concurrent.locks.Lock obtain(java.lang.Object lockKey)