public void lock(final long recid) { if (CC.LOG_LOCKS) Utils.LOG.finest("TRYLOCK R:" + recid + " T:" + Thread.currentThread().getId()); // feel free to rewrite, if you know better (more efficient) way if (CC.ASSERT && locks.get(recid) == Thread.currentThread()) { // check node is not already locked by this thread throw new InternalError("node already locked by current thread: " + recid); } while (locks.putIfAbsent(recid, Thread.currentThread()) != null) { Thread.yield(); } if (CC.LOG_LOCKS) Utils.LOG.finest("LOCK R:" + recid + " T:" + Thread.currentThread().getId()); }