question: public static < T extends Throwable > void lockAndThen ( ReentrantLock lock , ExceptionalRunnable < T > code ) throws T { if ( lock . isHeldByCurrentThread ( ) ) { code . run ( ) ; } else { lock . lock ( ) ; try { code . run ( ) ; } finally { lock . unlock ( ) ; } } }
target:  Acquires lock if the current thread does not hold it already, executes code and returns. The passed lambda may throw an exception, which is then thrown by this method.