On Tue, 21 Jun 2022 17:08:17 GMT, liach <d...@openjdk.org> wrote: >> @liach advance apologies for nitpicking: `ConcurrentHashMap` doesn't in >> general block while the mapping function runs. It can block _some_ >> concurrent updates, namely those that [hash to the same >> bin](https://github.com/openjdk/jdk/blob/0f801fe6fd2fcc181121f9846f6869ca3a03e18a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java#L324) >> and it won't block concurrent reads. I'm not saying the concern you raised >> isn't valid, just wanted to clarify that the situation is not nearly as >> grave as overall blocking; after all it ain't a >> `Collections.synchronizedMap` :-) > > Yeah, since `putIfAbsent` may block `get` calls, the blocking of > `computeIfAbsent` is minuscule as long as the creation code is efficient > enough. Just be careful that when writing the lambda for `computeIfAbsent`, > preferably write static lambdas (that doesn't use `this`, instances, or local > variables) so that one lambda can be reused over time than having to create a > new one on each invocation.
Updated ------------- PR: https://git.openjdk.org/jdk/pull/9208