提交 ca251265 编写于 作者: J jlahoda

8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs

Summary: Making Preferences.systemRoot/userRoot lazy on Windows, to avoid warnings for system root when only user root was requested; reducing synchronization while creating the Preferences.
Reviewed-by: alanb
上级 edf68627
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2018, 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
...@@ -47,27 +47,39 @@ class MacOSXPreferences extends AbstractPreferences { ...@@ -47,27 +47,39 @@ class MacOSXPreferences extends AbstractPreferences {
private final String path; private final String path;
// User root and system root nodes // User root and system root nodes
private static MacOSXPreferences userRoot = null; private static volatile MacOSXPreferences userRoot;
private static MacOSXPreferences systemRoot = null; private static volatile MacOSXPreferences systemRoot;
// Returns user root node, creating it if necessary. // Returns user root node, creating it if necessary.
// Called by MacOSXPreferencesFactory // Called by MacOSXPreferencesFactory
static synchronized Preferences getUserRoot() { static Preferences getUserRoot() {
if (userRoot == null) { MacOSXPreferences root = userRoot;
userRoot = new MacOSXPreferences(true); 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. // Returns system root node, creating it if necessary.
// Called by MacOSXPreferencesFactory // Called by MacOSXPreferencesFactory
static synchronized Preferences getSystemRoot() { static Preferences getSystemRoot() {
if (systemRoot == null) { MacOSXPreferences root = systemRoot;
systemRoot = new MacOSXPreferences(false); if (root == null) {
synchronized (MacOSXPreferences.class) {
root = systemRoot;
if (root == null) {
systemRoot = root = new MacOSXPreferences(false);
}
}
} }
return systemRoot; return root;
} }
......
/* /*
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2018, 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
...@@ -88,14 +88,20 @@ class FileSystemPreferences extends AbstractPreferences { ...@@ -88,14 +88,20 @@ class FileSystemPreferences extends AbstractPreferences {
/** /**
* The user root. * The user root.
*/ */
static Preferences userRoot = null; private static volatile Preferences userRoot;
static synchronized Preferences getUserRoot() { static Preferences getUserRoot() {
if (userRoot == null) { Preferences root = userRoot;
setupUserRoot(); if (root == null) {
userRoot = new FileSystemPreferences(true); synchronized (FileSystemPreferences.class) {
root = userRoot;
if (root == null) {
setupUserRoot();
userRoot = root = new FileSystemPreferences(true);
}
}
} }
return userRoot; return root;
} }
private static void setupUserRoot() { private static void setupUserRoot() {
...@@ -149,14 +155,20 @@ class FileSystemPreferences extends AbstractPreferences { ...@@ -149,14 +155,20 @@ class FileSystemPreferences extends AbstractPreferences {
/** /**
* The system root. * The system root.
*/ */
static Preferences systemRoot; private static volatile Preferences systemRoot;
static synchronized Preferences getSystemRoot() { static Preferences getSystemRoot() {
if (systemRoot == null) { Preferences root = systemRoot;
setupSystemRoot(); if (root == null) {
systemRoot = new FileSystemPreferences(false); synchronized (FileSystemPreferences.class) {
root = systemRoot;
if (root == null) {
setupSystemRoot();
systemRoot = root = new FileSystemPreferences(false);
}
}
} }
return systemRoot; return root;
} }
private static void setupSystemRoot() { private static void setupSystemRoot() {
......
/* /*
* Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2018, 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
...@@ -82,14 +82,40 @@ class WindowsPreferences extends AbstractPreferences{ ...@@ -82,14 +82,40 @@ class WindowsPreferences extends AbstractPreferences{
/** /**
* User root node. * User root node.
*/ */
static final Preferences userRoot = private static volatile Preferences userRoot;
new WindowsPreferences(USER_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);
static Preferences getUserRoot() {
Preferences root = userRoot;
if (root == null) {
synchronized (WindowsPreferences.class) {
root = userRoot;
if (root == null) {
root = new WindowsPreferences(USER_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);
userRoot = root;
}
}
}
return root;
}
/** /**
* System root node. * System root node.
*/ */
static final Preferences systemRoot = private static volatile Preferences systemRoot;
new WindowsPreferences(SYSTEM_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);
static Preferences getSystemRoot() {
Preferences root = systemRoot;
if (root == null) {
synchronized (WindowsPreferences.class) {
root = systemRoot;
if (root == null) {
root = new WindowsPreferences(SYSTEM_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);
systemRoot = root;
}
}
}
return root;
}
/* Windows error codes. */ /* Windows error codes. */
private static final int ERROR_SUCCESS = 0; private static final int ERROR_SUCCESS = 0;
......
/* /*
* Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2018, 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
...@@ -39,13 +39,13 @@ class WindowsPreferencesFactory implements PreferencesFactory { ...@@ -39,13 +39,13 @@ class WindowsPreferencesFactory implements PreferencesFactory {
* Returns WindowsPreferences.userRoot * Returns WindowsPreferences.userRoot
*/ */
public Preferences userRoot() { public Preferences userRoot() {
return WindowsPreferences.userRoot; return WindowsPreferences.getUserRoot();
} }
/** /**
* Returns WindowsPreferences.systemRoot * Returns WindowsPreferences.systemRoot
*/ */
public Preferences systemRoot() { public Preferences systemRoot() {
return WindowsPreferences.systemRoot; return WindowsPreferences.getSystemRoot();
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册