org.springframework.integration.util
Class DefaultLockRegistry

java.lang.Object
  extended by org.springframework.integration.util.DefaultLockRegistry
All Implemented Interfaces:
LockRegistry

public final class DefaultLockRegistry
extends java.lang.Object
implements LockRegistry

Default implementation of LockRegistry which uses Masked Hashcode algorithm to obtain locks. When an instance of this class is created and array of Lock objects 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 ReentrantLock instances. When the obtain(Object) method is called with the lockKey (e.g., Object) the index of the Lock is determined by masking the object's hashCode (e.g., object.hashCode & mask) and the Lock is returned.

Since:
2.0.6

Constructor Summary
DefaultLockRegistry()
          Constructs a DefaultLockRegistry with the default mask 0xFF with 256 locks.
DefaultLockRegistry(int mask)
          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.
 
Method Summary
 java.util.concurrent.locks.Lock obtain(java.lang.Object lockKey)
          Obtains a lock by masking the lockKey's hashCode() with the mask and using the result as an index to the lock table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultLockRegistry

public DefaultLockRegistry()
Constructs a DefaultLockRegistry with the default mask 0xFF with 256 locks.


DefaultLockRegistry

public DefaultLockRegistry(int mask)
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.

Examples:

  • 0x3ff (1023) - 1024 locks
  • 0xfff (4095) - 4096 locks
  • Parameters:
    mask -
    Method Detail

    obtain

    public java.util.concurrent.locks.Lock obtain(java.lang.Object lockKey)
    Obtains a lock by masking the lockKey's hashCode() with the mask and using the result as an index to the lock table.

    Specified by:
    obtain in interface LockRegistry
    Parameters:
    lockKey - the object used to derive the lock index.
    Returns:
    The associated lock.