Robert

76%
Flag icon
In fact, you can do even better. ConcurrentHashMap is optimized for retrieval operations, such as get. Therefore, it is worth invoking get initially and calling putIfAbsent only if get indicates that it is necessary:
Robert
Not that I have a problem with this, but this kinda _seems_ like it contradicts earlier recommendations to only optimize after knowing it's necessary. I guess when it comes to concurrency, the value of optimizing is higher, making it worth it more often. Almost seems worth explicitly calling that out.
Effective Java
Rate this book
Clear rating
Open Preview