public boolean isHeldByCurrentThread(long id) {
    Thread currentThread = Thread.currentThread();
    Entry entry = map.get(id);
    if (entry == null) {
      return false;
    }
    synchronized (entry) {
      return currentThread.equals(entry.holder);
    }
  }
Test whether the given id is already locked by the current thread.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/IdLock.java