Code example for ReentrantLock

Methods: isHeldByCurrentThread, isLocked, unlock

0
            lock.unlock();
         } 
      } 
 
      private String lockInfo() {
         return " Is locked? " + lock.isLocked() + ". Lock held by me? " + lock.isHeldByCurrentThread();
      } 
 
      public void block() { 
         log.trace("block. " + lockInfo());
         lock.lock();
      } 
 
      public void allow() { 
         log.trace("allow." + lockInfo());
         lock.unlock();
      } 
   } 
}