提交 42eb73f2 编写于 作者: C coffeys

7196533: TimeZone.getDefault() slow due to synchronization bottleneck

Reviewed-by: okutsu
上级 06cf8054
/* /*
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -719,15 +719,16 @@ abstract public class TimeZone implements Serializable, Cloneable { ...@@ -719,15 +719,16 @@ abstract public class TimeZone implements Serializable, Cloneable {
* Returns the default TimeZone in an AppContext if any AppContext * Returns the default TimeZone in an AppContext if any AppContext
* has ever used. null is returned if any AppContext hasn't been * has ever used. null is returned if any AppContext hasn't been
* used or if the AppContext doesn't have the default TimeZone. * used or if the AppContext doesn't have the default TimeZone.
*
* Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't
* been loaded. If so, it implies that AWTSecurityManager is not our
* SecurityManager and we can use a local static variable.
* This works around a build time issue.
*/ */
private synchronized static TimeZone getDefaultInAppContext() { private static TimeZone getDefaultInAppContext() {
// JavaAWTAccess provides access implementation-private methods without using reflection. // JavaAWTAccess provides access implementation-private methods without using reflection.
JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess(); JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess();
// Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't
// been loaded. If so, it implies that AWTSecurityManager is not our
// SecurityManager and we can use a local static variable.
// This works around a build time issue.
if (javaAWTAccess == null) { if (javaAWTAccess == null) {
return mainAppContextDefault; return mainAppContextDefault;
} else { } else {
...@@ -749,15 +750,16 @@ abstract public class TimeZone implements Serializable, Cloneable { ...@@ -749,15 +750,16 @@ abstract public class TimeZone implements Serializable, Cloneable {
* tz. null is handled special: do nothing if any AppContext * tz. null is handled special: do nothing if any AppContext
* hasn't been used, remove the default TimeZone in the * hasn't been used, remove the default TimeZone in the
* AppContext otherwise. * AppContext otherwise.
*
* Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't
* been loaded. If so, it implies that AWTSecurityManager is not our
* SecurityManager and we can use a local static variable.
* This works around a build time issue.
*/ */
private synchronized static void setDefaultInAppContext(TimeZone tz) { private static void setDefaultInAppContext(TimeZone tz) {
// JavaAWTAccess provides access implementation-private methods without using reflection. // JavaAWTAccess provides access implementation-private methods without using reflection.
JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess(); JavaAWTAccess javaAWTAccess = SharedSecrets.getJavaAWTAccess();
// Note that javaAWTAccess may be null if sun.awt.AppContext class hasn't
// been loaded. If so, it implies that AWTSecurityManager is not our
// SecurityManager and we can use a local static variable.
// This works around a build time issue.
if (javaAWTAccess == null) { if (javaAWTAccess == null) {
mainAppContextDefault = tz; mainAppContextDefault = tz;
} else { } else {
...@@ -822,7 +824,7 @@ abstract public class TimeZone implements Serializable, Cloneable { ...@@ -822,7 +824,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
private static final int GMT_ID_LENGTH = 3; private static final int GMT_ID_LENGTH = 3;
// a static TimeZone we can reference if no AppContext is in place // a static TimeZone we can reference if no AppContext is in place
private static TimeZone mainAppContextDefault; private static volatile TimeZone mainAppContextDefault;
/** /**
* Parses a custom time zone identifier and returns a corresponding zone. * Parses a custom time zone identifier and returns a corresponding zone.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册