jdk/src/share/classes/java/util/logging/LogManager.java
changeset 22342 c83795c442b7
parent 22110 06e486bc20b6
parent 22332 fba4c66089bb
child 23342 d7a41da68b85
equal deleted inserted replaced
22256:191b8793a532 22342:c83795c442b7
   238      * (such as J2EE containers) can subclass the object.  It is non-public as
   238      * (such as J2EE containers) can subclass the object.  It is non-public as
   239      * it is intended that there only be one LogManager object, whose value is
   239      * it is intended that there only be one LogManager object, whose value is
   240      * retrieved by calling LogManager.getLogManager.
   240      * retrieved by calling LogManager.getLogManager.
   241      */
   241      */
   242     protected LogManager() {
   242     protected LogManager() {
       
   243         this(checkSubclassPermissions());
       
   244     }
       
   245 
       
   246     private LogManager(Void checked) {
       
   247 
   243         // Add a shutdown hook to close the global handlers.
   248         // Add a shutdown hook to close the global handlers.
   244         try {
   249         try {
   245             Runtime.getRuntime().addShutdownHook(new Cleaner());
   250             Runtime.getRuntime().addShutdownHook(new Cleaner());
   246         } catch (IllegalStateException e) {
   251         } catch (IllegalStateException e) {
   247             // If the VM is already shutting down,
   252             // If the VM is already shutting down,
   248             // We do not need to register shutdownHook.
   253             // We do not need to register shutdownHook.
   249         }
   254         }
       
   255     }
       
   256 
       
   257     private static Void checkSubclassPermissions() {
       
   258         final SecurityManager sm = System.getSecurityManager();
       
   259         if (sm != null) {
       
   260             // These permission will be checked in the LogManager constructor,
       
   261             // in order to register the Cleaner() thread as a shutdown hook.
       
   262             // Check them here to avoid the penalty of constructing the object
       
   263             // etc...
       
   264             sm.checkPermission(new RuntimePermission("shutdownHooks"));
       
   265             sm.checkPermission(new RuntimePermission("setContextClassLoader"));
       
   266         }
       
   267         return null;
   250     }
   268     }
   251 
   269 
   252     /**
   270     /**
   253      * Lazy initialization: if this instance of manager is the global
   271      * Lazy initialization: if this instance of manager is the global
   254      * manager then this method will read the initial configuration and
   272      * manager then this method will read the initial configuration and