Class JdbcLockRegistry

java.lang.Object
org.springframework.integration.jdbc.lock.JdbcLockRegistry
All Implemented Interfaces:
org.springframework.integration.support.locks.ExpirableLockRegistry<org.springframework.integration.support.locks.DistributedLock>, org.springframework.integration.support.locks.LockRegistry<org.springframework.integration.support.locks.DistributedLock>, org.springframework.integration.support.locks.RenewableLockRegistry<org.springframework.integration.support.locks.DistributedLock>

public class JdbcLockRegistry extends Object implements org.springframework.integration.support.locks.ExpirableLockRegistry<org.springframework.integration.support.locks.DistributedLock>, org.springframework.integration.support.locks.RenewableLockRegistry<org.springframework.integration.support.locks.DistributedLock>
An ExpirableLockRegistry using a shared database to co-ordinate the locks. Provides the same semantics as the DefaultLockRegistry, but the locks taken will be global, as long as the underlying database supports the "serializable" isolation level in its transactions.

The lock instances are cached by their key for future reuse. If all the locks in the cache are acquired, the obtain(Object) method throws CannotAcquireLockException. Otherwise, the old, unused locks are evicted from the cache. An attempt to lock such an orphaned JdbcLockRegistry.JdbcLock throws another CannotAcquireLockException to avoid double locking from different threads on the same key.

Since:
4.3
  • Field Details

    • DEFAULT_TTL

      public static final Duration DEFAULT_TTL
      Default value for the time-to-live property.
      Since:
      7.0
  • Constructor Details

    • JdbcLockRegistry

      public JdbcLockRegistry(LockRepository client)
      Construct an instance based on the provided LockRepository.
      Parameters:
      client - the LockRepository to rely on.
    • JdbcLockRegistry

      public JdbcLockRegistry(LockRepository client, Duration expireAfter)
      Create a lock registry with the supplied lock expiration.
      Parameters:
      client - the LockRepository to rely on.
      expireAfter - The expiration in Duration.
      Since:
      7.0
  • Method Details

    • setIdleBetweenTries

      public void setIdleBetweenTries(Duration idleBetweenTries)
      Specify a Duration to sleep between lock record insert/update attempts. Defaults to 100 milliseconds.
      Parameters:
      idleBetweenTries - the Duration to sleep between insert/update attempts.
      Since:
      5.1.8
    • setCacheCapacity

      public void setCacheCapacity(int cacheCapacity)
      Set the capacity of cached locks. If the number of currently cached locks exceeds the new capacity, this method tries to evict unused locks.
      Parameters:
      cacheCapacity - The capacity of cached lock, (default 100_000).
      Since:
      5.5.6
      See Also:
    • obtain

      public org.springframework.integration.support.locks.DistributedLock obtain(Object lockKey)
      Specified by:
      obtain in interface org.springframework.integration.support.locks.LockRegistry<org.springframework.integration.support.locks.DistributedLock>
    • pathFor

      protected String pathFor(String input)
    • expireUnusedOlderThan

      public void expireUnusedOlderThan(long age)
      Specified by:
      expireUnusedOlderThan in interface org.springframework.integration.support.locks.ExpirableLockRegistry<org.springframework.integration.support.locks.DistributedLock>
    • renewLock

      public void renewLock(Object lockKey)
      Specified by:
      renewLock in interface org.springframework.integration.support.locks.RenewableLockRegistry<org.springframework.integration.support.locks.DistributedLock>
    • renewLock

      public void renewLock(Object lockKey, Duration customTtl)
      Specified by:
      renewLock in interface org.springframework.integration.support.locks.RenewableLockRegistry<org.springframework.integration.support.locks.DistributedLock>
    • toString

      public String toString()
      Overrides:
      toString in class Object