Class LockSupport

    • Method Detail

      • acquireReadLock

        protected final void acquireReadLock()
        Locks the shared read lock. Any number of threads may lock the read lock at the same time.
      • takeWriteLock

        protected final void takeWriteLock()
        Takes the exclusive write lock. Once started, no other thread lock the read or write lock. When this method returns, this thread will have locked the write lock and no other thread will have either the read or write lock. Note that this thread must first drop the read lock (if it has it) before attempting to take the write lock, or this method will block forever.
      • releaseReadLock

        protected final void releaseReadLock()
        Releases the shared read lock.
      • releaseWriteLock

        protected final void releaseWriteLock()
        Releases the exclusive read lock.
      • upgradeReadLockToWriteLock

        protected final void upgradeReadLockToWriteLock()
        Releases the read lock, then takes the write lock. There's a short window where the thread will have neither lock: during that window, some other thread may have a chance to take the write lock. In code, you'll often see a second check inside the code that has the write lock to see if the update to perform is still necessary.