src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferencesFile.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) 2011, 2013, 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 
  28 import java.util.HashMap;
  29 import java.util.HashSet;
  30 import java.util.Iterator;
  31 import java.util.Timer;
  32 import java.util.TimerTask;
  33 import java.lang.ref.WeakReference;
  34 import sun.misc.ManagedLocalsThread;
  35 
  36 
  37 /*
  38   MacOSXPreferencesFile synchronization:
  39 
  40   Everything is synchronized on MacOSXPreferencesFile.class. This prevents:
  41   * simultaneous updates to cachedFiles or changedFiles
  42   * simultaneous creation of two objects for the same name+user+host triplet
  43   * simultaneous modifications to the same file
  44   * modifications during syncWorld/flushWorld
  45   * (in MacOSXPreferences.removeNodeSpi()) modification or sync during
  46     multi-step node removal process
  47   ... among other things.
  48 */
  49 /*
  50   Timers. There are two timers that control synchronization of prefs data to
  51   and from disk.
  52 
  53   * Sync timer periodically calls syncWorld() to force external disk changes
  54       (e.g. from another VM) into the memory cache. The sync timer runs even


 327                 syncInterval = -2; // bad property value - default off
 328             }
 329 
 330             if (syncInterval > 0) {
 331                 timer().schedule(new TimerTask() {
 332                     @Override
 333                     public void run() {
 334                         MacOSXPreferencesFile.syncWorld();}
 335                     }, syncInterval * 1000, syncInterval * 1000);
 336             } else {
 337                 // syncInterval property not set. No sync timer ever.
 338             }
 339         }
 340     }
 341 
 342     // Return the timer used for flush and sync, creating it if necessary.
 343     private static synchronized Timer timer()
 344     {
 345         if (timer == null) {
 346             timer = new Timer(true); // daemon
 347             Thread flushThread = new ManagedLocalsThread() {

 348                 @Override
 349                 public void run() {
 350                     flushWorld();
 351                 }
 352             };
 353             /* Set context class loader to null in order to avoid
 354              * keeping a strong reference to an application classloader.
 355              */
 356             flushThread.setContextClassLoader(null);
 357             Runtime.getRuntime().addShutdownHook(flushThread);
 358         }
 359         return timer;
 360     }
 361 
 362 
 363     // Node manipulation
 364     boolean addNode(String path)
 365     {
 366         synchronized(MacOSXPreferencesFile.class) {
 367             markChanged();


   1 /*
   2  * Copyright (c) 2011, 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 
  28 import java.util.HashMap;
  29 import java.util.HashSet;
  30 import java.util.Iterator;
  31 import java.util.Timer;
  32 import java.util.TimerTask;
  33 import java.lang.ref.WeakReference;

  34 
  35 
  36 /*
  37   MacOSXPreferencesFile synchronization:
  38 
  39   Everything is synchronized on MacOSXPreferencesFile.class. This prevents:
  40   * simultaneous updates to cachedFiles or changedFiles
  41   * simultaneous creation of two objects for the same name+user+host triplet
  42   * simultaneous modifications to the same file
  43   * modifications during syncWorld/flushWorld
  44   * (in MacOSXPreferences.removeNodeSpi()) modification or sync during
  45     multi-step node removal process
  46   ... among other things.
  47 */
  48 /*
  49   Timers. There are two timers that control synchronization of prefs data to
  50   and from disk.
  51 
  52   * Sync timer periodically calls syncWorld() to force external disk changes
  53       (e.g. from another VM) into the memory cache. The sync timer runs even


 326                 syncInterval = -2; // bad property value - default off
 327             }
 328 
 329             if (syncInterval > 0) {
 330                 timer().schedule(new TimerTask() {
 331                     @Override
 332                     public void run() {
 333                         MacOSXPreferencesFile.syncWorld();}
 334                     }, syncInterval * 1000, syncInterval * 1000);
 335             } else {
 336                 // syncInterval property not set. No sync timer ever.
 337             }
 338         }
 339     }
 340 
 341     // Return the timer used for flush and sync, creating it if necessary.
 342     private static synchronized Timer timer()
 343     {
 344         if (timer == null) {
 345             timer = new Timer(true); // daemon
 346             Thread flushThread =
 347                 new Thread(null, null, "Flush Thread", 0, false) {
 348                 @Override
 349                 public void run() {
 350                     flushWorld();
 351                 }
 352             };
 353             /* Set context class loader to null in order to avoid
 354              * keeping a strong reference to an application classloader.
 355              */
 356             flushThread.setContextClassLoader(null);
 357             Runtime.getRuntime().addShutdownHook(flushThread);
 358         }
 359         return timer;
 360     }
 361 
 362 
 363     // Node manipulation
 364     boolean addNode(String path)
 365     {
 366         synchronized(MacOSXPreferencesFile.class) {
 367             markChanged();