--- a/jdk/src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferences.java Mon Jun 13 00:47:32 2016 -0700
+++ b/jdk/src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferences.java Mon Jun 13 11:46:07 2016 +0200
@@ -44,27 +44,39 @@
private final String path;
// User root and system root nodes
- private static MacOSXPreferences userRoot = null;
- private static MacOSXPreferences systemRoot = null;
+ private static volatile MacOSXPreferences userRoot;
+ private static volatile MacOSXPreferences systemRoot;
// Returns user root node, creating it if necessary.
// Called by MacOSXPreferencesFactory
- static synchronized Preferences getUserRoot() {
- if (userRoot == null) {
- userRoot = new MacOSXPreferences(true);
+ static Preferences getUserRoot() {
+ MacOSXPreferences root = userRoot;
+ if (root == null) {
+ synchronized (MacOSXPreferences.class) {
+ root = userRoot;
+ if (root == null) {
+ userRoot = root = new MacOSXPreferences(true);
+ }
+ }
}
- return userRoot;
+ return root;
}
// Returns system root node, creating it if necessary.
// Called by MacOSXPreferencesFactory
- static synchronized Preferences getSystemRoot() {
- if (systemRoot == null) {
- systemRoot = new MacOSXPreferences(false);
+ static Preferences getSystemRoot() {
+ MacOSXPreferences root = systemRoot;
+ if (root == null) {
+ synchronized (MacOSXPreferences.class) {
+ root = systemRoot;
+ if (root == null) {
+ systemRoot = root = new MacOSXPreferences(false);
+ }
+ }
}
- return systemRoot;
+ return root;
}