Class of the day: ConcurrentHashMap


Well today at work involved me using ConcurrentHashMap and in particular putIfAbsent to severely reduce the need for old-school synchronized blocks.

Just a shame that you can't pass in arbitrary expressions/blocks that will only be evaluated if the value isn't present when you call putIfAbsent. Might become feasible if Java gets closures. There's definitely some power in the java.util.concurrent package though.

Still it's been a while since I've had that kind of satisfaction writing Java code.