Monitor lock in RuleBasedCollator?

时间:2016-02-12 21:16:01

标签: java multithreading locking

Ok, so I'm trying to find out why some threaded code is bottlenecking, and looking at thread dumps, it appears that java.text.RuleBasedCollator.compare is locking a RuleBasedCollator object.

However, I look at that code, and there are no synchronized sections of code that could be setting this monitor lock on code. As far as I know, the only way in Java to obtain a lock is in a section of synchronized code. Below I have included the stack dump for 1) the thread that owns the lock, and 2) the thread that is waiting on it. If you need any more info, let me know.

THREAD HOLDING THE LOCK:

for(int i =0; i<seconds; i++)
{
        currentTemp -= currentTemp*K*(currentTemp - FREEZER_TEMPERATURE);
} 

THREAD AWAITING LOCK:

Owns Monitor Lock on 0xc6f85460
Java Stack
at sun.text.normalizer.ReplaceableUCharacterIterator.(ReplaceableUCharacterIterator.java:44) 
at sun.text.normalizer.UCharacterIterator.getInstance(UCharacterIterator.java:66) 
at sun.text.normalizer.NormalizerBase.setText(NormalizerBase.java:985) 
at java.text.CollationElementIterator.setText(CollationElementIterator.java:480) 
at java.text.RuleBasedCollator.compare(RuleBasedCollator.java:353) 
- locked [0xc6f85460] (a java.text.RuleBasedCollator) 
at java.text.Collator.compare(Collator.java:310) 
at java.util.Arrays.binarySearch0(Arrays.java:2105) 
at java.util.Arrays.binarySearch(Arrays.java:2043) 
at org.apache.axis.utils.JavaUtils.isJavaKeyword(JavaUtils.java:740)

Any insight would be appreciated.

1 个答案:

答案 0 :(得分:0)

您没有说出您正在使用的Java版本,但在Java 8中,RuleBasedCollat​​or中的compare方法已同步:

public synchronized int compare(String source, String target)

这可以解释你看到的线程转储。