hg: jdk8/tl/jdk: 7145454: JVM wide monitor lock in Currency.getInstance(String) (original) (raw)

Naoto Sato naoto.sato at oracle.com
Thu Mar 22 15:33:26 UTC 2012


Hi David,

Sorry, the review was done in the i18n team and did not go to core libs alias.

In your suggested fix, I think there is a very slight chance that two threads could get different Currency instances if the first thread was interrupted just after instantiating "currencyVal" instance, which has not been the case in the prior implementation. Although returning the singleton instance is not mandated by the spec, I though it is safer to keep the same behavior and that get() cost is almost negligible.

Naoto

On 3/21/12 7:27 P, David Holmes wrote:

Hi,

I'm sorry I missed the review of this change. The following is somewhat inefficient: instance = instances.putIfAbsent(currencyCode, new Currency(currencyCode, defaultFractionDigits, numericCode)); return (instance != null ? instance : instances.get(currencyCode)); If the putIfAbsent succeeds then the value to return is the newly constructed Currency instance. So if we track that object then we don't need to do the additional get(): Currency currencyVal = new Currency(currencyCode, defaultFractionDigits, numericCode); instance = instances.putIfAbsent(currencyCode, currencyVal); return (instance != null ? instance : currencyVal); Cheers, David

On 22/03/2012 3:12 AM, naoto.sato at oracle.com wrote: Changeset: 4a5817f9e249 Author: naoto Date: 2012-03-21 10:10 -0700 URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/4a5817f9e249

7145454: JVM wide monitor lock in Currency.getInstance(String) Reviewed-by: okutsu ! src/share/classes/java/util/Currency.java



More information about the core-libs-dev mailing list