Skip to content

Commit 1f4134e

Browse files
Kieran Farrellnaotoj
authored andcommitted
8367237: Thread-Safety Usage Warning for java.text.Collator Classes
Reviewed-by: jlu Backport-of: 64155dfac068cf01bcab6adb401b360499f33a5f
1 parent ef2719a commit 1f4134e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/java.base/share/classes/java/text/Collator.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@
111111
* <br>
112112
* @apiNote {@code CollationKey}s from different
113113
* {@code Collator}s can not be compared. See the class description
114-
* for {@link CollationKey}
115-
* for an example using {@code CollationKey}s.
114+
* for {@link CollationKey} for an example using {@code CollationKey}s.
115+
*
116+
* @implNote Significant thread contention may occur during concurrent usage
117+
* of the JDK Reference Implementation's {@link RuleBasedCollator}, which is the
118+
* subtype returned by the default provider of the {@link #getInstance()} factory
119+
* methods. As such, users should consider retrieving a separate instance for
120+
* each thread when used in multithreaded environments.
116121
*
117122
* @see RuleBasedCollator
118123
* @see CollationKey

src/java.base/share/classes/java/text/RuleBasedCollator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -38,10 +38,6 @@
3838

3939
package java.text;
4040

41-
import java.text.Normalizer;
42-
import java.util.Vector;
43-
import java.util.Locale;
44-
4541
/**
4642
* The {@code RuleBasedCollator} class is a concrete subclass of
4743
* {@code Collator} that provides a simple, data-driven, table
@@ -239,6 +235,11 @@
239235
* </pre>
240236
* </blockquote>
241237
*
238+
* @implNote For this implementation, concurrent usage of this class may
239+
* lead to significant thread contention since {@code synchronized} is employed
240+
* to ensure thread-safety. As such, users of this class should consider creating
241+
* a separate instance for each thread when used in multithreaded environments.
242+
*
242243
* @see Collator
243244
* @see CollationElementIterator
244245
* @author Helena Shih, Laura Werner, Richard Gillam

0 commit comments

Comments
 (0)