Class KeyedReentrantReadWriteLock

java.lang.Object
org.apache.tomcat.util.concurrent.KeyedReentrantReadWriteLock

public class KeyedReentrantReadWriteLock extends Object
Provides a reentrant read/write lock for a given key. Any locks obtained from an instance of this class using the same key will use the same underlying reentrant read/write lock as long as at least one lock for that key remains in use. Once no locks are in use for the given key, the lock is eligible for GC and the next lock obtained using that key will use a new underlying reentrant read/write lock.

The class is used when Tomcat needs to manage concurrent access to components identified by a key (e.g. sessions).

The map of keys to locks is maintained so that locks are created as required and removed when no longer used.

The locks provided by this class only implement Lock#lock() and Lock#unlock(). All other methods will throw UnsupportedOperationException.

  • Constructor Details

    • KeyedReentrantReadWriteLock

      public KeyedReentrantReadWriteLock()
  • Method Details

    • getLock

      public ReadWriteLock getLock(String key)
      Obtain the reentrant read/write lock for the given key.
      Parameters:
      key - The key for which the lock should be obtained
      Returns:
      A reentrant read/write lock for the given key