src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java

Print this page
rev 13541 : 8147545: Remove sun.misc.ManagedLocalsThread from java.prefs
Summary: Replace ManagedLocalsThread with Thread(null,null,threadName,0,false)
Reviewed-by: XXX
   1 /*
   2  * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.prefs;
  27 import java.util.*;
  28 import java.io.*;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedAction;
  31 import java.security.PrivilegedExceptionAction;
  32 import java.security.PrivilegedActionException;
  33 import sun.misc.ManagedLocalsThread;
  34 import sun.util.logging.PlatformLogger;
  35 
  36 /**
  37  * Preferences implementation for Unix.  Preferences are stored in the file
  38  * system, with one directory per preferences node.  All of the preferences
  39  * at each node are stored in a single file.  Atomic file system operations
  40  * (e.g. File.renameTo) are used to ensure integrity.  An in-memory cache of
  41  * the "explored" portion of the tree is maintained for performance, and
  42  * written back to the disk periodically.  File-locking is used to ensure
  43  * reasonable behavior when multiple VMs are running at the same time.
  44  * (The file lock is obtained only for sync(), flush() and removeNode().)
  45  *
  46  * @author  Josh Bloch
  47  * @see     Preferences
  48  * @since   1.4
  49  */
  50 class FileSystemPreferences extends AbstractPreferences {
  51 
  52     static {
  53         PrivilegedAction<Void> load = () -> {


 426      * Replay changeLog against prefsCache.
 427      */
 428     private void replayChanges() {
 429         for (int i = 0, n = changeLog.size(); i<n; i++)
 430             changeLog.get(i).replay();
 431     }
 432 
 433     private static Timer syncTimer = new Timer(true); // Daemon Thread
 434 
 435     static {
 436         // Add periodic timer task to periodically sync cached prefs
 437         syncTimer.schedule(new TimerTask() {
 438             public void run() {
 439                 syncWorld();
 440             }
 441         }, SYNC_INTERVAL*1000, SYNC_INTERVAL*1000);
 442 
 443         // Add shutdown hook to flush cached prefs on normal termination
 444         AccessController.doPrivileged(new PrivilegedAction<Void>() {
 445             public Void run() {
 446                 Runtime.getRuntime().addShutdownHook(new ManagedLocalsThread() {

 447                     public void run() {
 448                         syncTimer.cancel();
 449                         syncWorld();
 450                     }
 451                 });
 452                 return null;
 453             }
 454         });
 455     }
 456 
 457     private static void syncWorld() {
 458         /*
 459          * Synchronization necessary because userRoot and systemRoot are
 460          * lazily initialized.
 461          */
 462         Preferences userRt;
 463         Preferences systemRt;
 464         synchronized(FileSystemPreferences.class) {
 465             userRt   = userRoot;
 466             systemRt = systemRoot;


   1 /*
   2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util.prefs;
  27 import java.util.*;
  28 import java.io.*;
  29 import java.security.AccessController;
  30 import java.security.PrivilegedAction;
  31 import java.security.PrivilegedExceptionAction;
  32 import java.security.PrivilegedActionException;

  33 import sun.util.logging.PlatformLogger;
  34 
  35 /**
  36  * Preferences implementation for Unix.  Preferences are stored in the file
  37  * system, with one directory per preferences node.  All of the preferences
  38  * at each node are stored in a single file.  Atomic file system operations
  39  * (e.g. File.renameTo) are used to ensure integrity.  An in-memory cache of
  40  * the "explored" portion of the tree is maintained for performance, and
  41  * written back to the disk periodically.  File-locking is used to ensure
  42  * reasonable behavior when multiple VMs are running at the same time.
  43  * (The file lock is obtained only for sync(), flush() and removeNode().)
  44  *
  45  * @author  Josh Bloch
  46  * @see     Preferences
  47  * @since   1.4
  48  */
  49 class FileSystemPreferences extends AbstractPreferences {
  50 
  51     static {
  52         PrivilegedAction<Void> load = () -> {


 425      * Replay changeLog against prefsCache.
 426      */
 427     private void replayChanges() {
 428         for (int i = 0, n = changeLog.size(); i<n; i++)
 429             changeLog.get(i).replay();
 430     }
 431 
 432     private static Timer syncTimer = new Timer(true); // Daemon Thread
 433 
 434     static {
 435         // Add periodic timer task to periodically sync cached prefs
 436         syncTimer.schedule(new TimerTask() {
 437             public void run() {
 438                 syncWorld();
 439             }
 440         }, SYNC_INTERVAL*1000, SYNC_INTERVAL*1000);
 441 
 442         // Add shutdown hook to flush cached prefs on normal termination
 443         AccessController.doPrivileged(new PrivilegedAction<Void>() {
 444             public Void run() {
 445                 Runtime.getRuntime().addShutdownHook(
 446                     new Thread(null, null, "Sync Timer Thread", 0, false) {
 447                     public void run() {
 448                         syncTimer.cancel();
 449                         syncWorld();
 450                     }
 451                 });
 452                 return null;
 453             }
 454         });
 455     }
 456 
 457     private static void syncWorld() {
 458         /*
 459          * Synchronization necessary because userRoot and systemRoot are
 460          * lazily initialized.
 461          */
 462         Preferences userRt;
 463         Preferences systemRt;
 464         synchronized(FileSystemPreferences.class) {
 465             userRt   = userRoot;
 466             systemRt = systemRoot;