Code example for ReentrantLock

Methods: isHeldByCurrentThread, isLocked, lock, unlock

0
      } 
 
      @Override 
      protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable {
         log.trace("Acquiring lock. " + lockInfo());
         lock.lock();
         try { 
            return super.handleDefault(ctx, command);
         } finally { 
            log.trace("Done operation, releasing lock" + lockInfo());
            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();