RFR: 8367237: Thread-Safety Usage Warning for java.text.Collator Classes
Naoto Sato
naoto at openjdk.org
Thu Sep 11 20:19:52 UTC 2025
On Thu, 11 Sep 2025 18:58:46 GMT, Justin Lu <jlu at openjdk.org> wrote:
> Please review this PR which is a documentation change to make apparent the recommended approach for using Collator & RuleBasedCollator in a multi threaded environment via an implNote. The original issue and CSR have additional context.
src/java.base/share/classes/java/text/Collator.java line 117:
> 115: *
> 116: * @implNote Concurrent usage of {@code Collator} instances returned by the factory
> 117: * methods under the standard provider may lead to significant thread contention.
"under the standard provider" may not be clear enough. How about "instances returned from the JDK's built-in implementation, `RuleBasedCollator`" or similar?
src/java.base/share/classes/java/text/RuleBasedCollator.java line 241:
> 239: * lead to significant thread contention. As such, users of this class should
> 240: * consider creating a separate instance for each thread when used in
> 241: * multithreaded environments.
I'd add the reason behind, i.e., RuleBasedCollator uses `synchronized` to make it thread-safe.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27233#discussion_r2342234118
PR Review Comment: https://git.openjdk.org/jdk/pull/27233#discussion_r2342236490
More information about the core-libs-dev
mailing list