JDK-7011025 : java.util.Currency.getInstance(String currencyCode) could perform much better
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 6u23
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2011-01-07
  • Updated: 2016-09-29
  • Resolved: 2016-09-29
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
The code in java.util.Currency.getInstance(String currencyCode, int defaultFractionDigits) is a static synchronized method (synchronizes on a static instance of a HashMap). Because of that, only one thread can access this method at a time. This may create thread contention in multithreaded JVMs (e.g. app. servers). There is no good reason for this method being synchronized.

JUSTIFICATION :
This may create thread contention in multithreaded JVMs (e.g. app. servers). There is no good reason for this method being synchronized. We learned this the hard way, by seeing degraded performance on our production Tomcat servers, and having to look at thread dumps to find this out.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code in java.util.Currency.getInstance(String currencyCode, int defaultFractionDigits) should not be synchronized.
ACTUAL -
The code in java.util.Currency.getInstance(String currencyCode, int defaultFractionDigits) is synchronized.

---------- BEGIN SOURCE ----------
Not needed. Just look at the code in java.util.Currency.getInstance(String currencyCode, int defaultFractionDigits)
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Create your own class that has a static method getInstance(String currencyCode). Make sure it is not synchronized. Cache all currencies used in your application in there at JVM startup.

Comments
This issue is already taken care in JDK-7145454
29-09-2016