Getting rid of boilerplate code for ReentrantReadWriteLock
Got tired of the idioms alike? rwl.readLock(); try { // thread // unsafe // code } finally { rwl.readLock().unlock(); } It is 2017 and Java 8 have been released in 2014! Using lamdas makes the code keen and clean. Here what you get: // You can assign the result to a variable of the type you need: String s = callReadLocked(() -> { // thread // unsafe // code return someString; }); } // If nothing needs to be returned, just return anything: callReadLocked(() -> { // thread // unsafe // code return null; }); } For the magic to work you need to define a couple of methods and a functional interface: private <T, E extends Throwab...