From b253560503b76cf1c489f01772d64a1132a9e96b Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Mon, 4 Nov 2019 14:54:06 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-23612=20=E3=80=90=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E3=80=91=E5=9B=BD=E9=99=85=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=80=A7=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ibm/icu/text/RuleBasedBreakIterator.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/fine-icu4j/src/com/fr/third/ibm/icu/text/RuleBasedBreakIterator.java b/fine-icu4j/src/com/fr/third/ibm/icu/text/RuleBasedBreakIterator.java index b202510ca..ce06a7f7f 100644 --- a/fine-icu4j/src/com/fr/third/ibm/icu/text/RuleBasedBreakIterator.java +++ b/fine-icu4j/src/com/fr/third/ibm/icu/text/RuleBasedBreakIterator.java @@ -17,6 +17,7 @@ import java.nio.ByteBuffer; import java.text.CharacterIterator; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.ReentrantReadWriteLock; import com.fr.third.ibm.icu.impl.CharacterIteration; import com.fr.third.ibm.icu.impl.ICUBinary; @@ -43,8 +44,11 @@ public class RuleBasedBreakIterator extends BreakIterator { */ private RuleBasedBreakIterator() { fDictionaryCharCount = 0; - synchronized(gAllBreakEngines) { + try { + rLock.lock(); fBreakEngines = new ArrayList(gAllBreakEngines); + } finally { + rLock.unlock(); } } @@ -131,8 +135,11 @@ public class RuleBasedBreakIterator extends BreakIterator { if (fText != null) { result.fText = (CharacterIterator)(fText.clone()); } - synchronized (gAllBreakEngines) { + try { + rLock.lock(); result.fBreakEngines = new ArrayList(gAllBreakEngines); + } finally { + rLock.unlock(); } result.fLookAheadMatches = new LookAheadResults(); result.fBreakCache = result.new BreakCache(fBreakCache); @@ -294,10 +301,19 @@ public class RuleBasedBreakIterator extends BreakIterator { */ private static final List gAllBreakEngines; + private static final ReentrantReadWriteLock rwLock; + + private static final ReentrantReadWriteLock.ReadLock rLock; + + private static final ReentrantReadWriteLock.WriteLock wLock; + static { gUnhandledBreakEngine = new UnhandledBreakEngine(); gAllBreakEngines = new ArrayList(); gAllBreakEngines.add(gUnhandledBreakEngine); + rwLock = new ReentrantReadWriteLock(); + rLock = rwLock.readLock(); + wLock = rwLock.writeLock(); } /** @@ -663,7 +679,8 @@ public class RuleBasedBreakIterator extends BreakIterator { } } - synchronized (gAllBreakEngines) { + try { + wLock.lock(); // This break iterator's list of break engines didn't handle the character. // Check the global list, another break iterator may have instantiated the // desired engine. @@ -717,7 +734,10 @@ public class RuleBasedBreakIterator extends BreakIterator { fBreakEngines.add(eng); } return eng; - } // end synchronized(gAllBreakEngines) + // end synchronized(gAllBreakEngines) + } finally { + wLock.unlock(); + } } private static final int kMaxLookaheads = 8;