package com.yahoo.concurrent.lock;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author valerijf
 */
public class Locking {
    private final Map<Class<?>, ReentrantLock> locks = new ConcurrentHashMap<>();

    /**
     * Locks class. This will block until the lock is acquired.
     * Users of this <b>must</b> close any lock acquired.
     *
     * @param key the key to lock
     * @return the acquired lock
     */
    public Lock lock(Class<?> key) {
        try {
            ReentrantLock lock = locks.computeIfAbsent(key, k -> new ReentrantLock(true));
            lock.tryLock(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
            return new Lock(lock);
        } catch (InterruptedException e) {
            throw new RuntimeException("Interrupted while waiting for lock of " + key);
        }
    }
}

@@ -102,46 +102,8 @@
 ap;%0A
-import java.util.concurrent.TimeUnit;%0A
 impo
@@ -535,26 +535,8 @@
 ) %7B%0A
-        try %7B%0A    
     
@@ -630,239 +630,51 @@
     
-    
 lock.
-tryLock(Long.MAX_VALUE, TimeUnit.NANOSECONDS);%0A            return new Lock(lock);%0A        %7D catch (InterruptedException e) %7B%0A            throw new RuntimeException(%22Interrupted while waiting for lock of %22 + key);%0A        %7D
+lock();%0A        return new Lock(lock);
 %0A   

Use lock instead