Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7011025

java.util.Currency.getInstance(String currencyCode) could perform much better

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u23
    • core-libs

      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.

            nishjain Nishit Jain
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: