Class KeyedReentrantReadWriteLock


  • public class KeyedReentrantReadWriteLock
    extends java.lang.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.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.locks.ReadWriteLock getLock​(java.lang.String key)
      Obtain the reentrant read/write lock for the given key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KeyedReentrantReadWriteLock

        public KeyedReentrantReadWriteLock()
    • Method Detail

      • getLock

        public java.util.concurrent.locks.ReadWriteLock getLock​(java.lang.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