If you want to do some form of memoization, then this is the best / easiest thing you can do in Java 7. Guava has a caching implementation for computing, and Java 8 has a computeIfAbsent method in Map , but you're clearly out of luck.
If you can create objects on an empty race, as Alexey says, this would be the best solution. If you do not, your implementation will be both thread-safe and reasonable.
This is a double-check lock form, however with this implementation you guarantee that this will happen before ordering using the put and get methods for CHM.
source share