RFR: 8299852: Modernize ConcurrentHashMap
Martin Buchholz
martin at openjdk.org
Tue Jan 10 22:57:15 UTC 2023
On Tue, 10 Jan 2023 10:32:34 GMT, Per Minborg <pminborg at openjdk.org> wrote:
> `java.util.concurrent.ConcurrentHashMap` is relatively old and has not been updated to reflect the current state of Java and can be modernized:
>
> * Add `@Serial` annotations
> * Seal classes and restrict subclassing for internal classes
> * Use pattern matching for instance
> * Remove redundant modifiers (such as some final declarations)
> * Use Objects.requireNonNull for invariant checking
> * Use diamond operators instead of explicit types
> * Simplify expressions using Math::max
src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java line 104:
> 102: * {@code size}, {@code isEmpty}, and {@code containsValue} are typically
> 103: * useful only when a map is not undergoing concurrent updates in other threads.
> 104: * Otherwise, the results of these methods reflect transient states
I agree the added comma here is an improvement.
src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java line 357:
> 355: * sometimes deviate significantly from uniform randomness. This
> 356: * includes the case when N > (1<<30), so some keys MUST collide.
> 357: * Similarly, for dumb or hostile usages in which multiple keys are
"Similarly" should almost always be followed by a comma, but this is an exception.
-------------
PR: https://git.openjdk.org/jdk/pull/11924
More information about the core-libs-dev
mailing list