Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Locale could be used in multithreaded application to improve performance

In my application I have a method which is called by multiple threads simultaneously. Each thread calls this method many times while running.

private Locale trLoc = new Locale("tr", "TR");

public double calculate(String arg1){
    arg1 = arg1.toUpperCase(trLoc);
...
}

This method makes a String.toUpperString(Locale) call which causes a bottleneck because of the HashTable usage within the Locale class. Each thread waits other one while toUpperCase method operates. This situation slows down my application up to three times.

Is there something I'm missing with the usage of the Locale or I must use another class for the same purpose?

Thanks in advance.

like image 636
Erdem Emekligil Avatar asked Aug 13 '15 12:08

Erdem Emekligil


1 Answers

After short exploring it looks like JDK can't help you. I suggest get java.lang.ConditionalSpecialCasing class, copy it and fix problem with Hashtable. You may replace Hashtable with HashMap. I do not see any reason for using Hashtable here.

like image 134
sibnick Avatar answered Oct 20 '22 18:10

sibnick