src/share/classes/java/util/logging/Logger.java

Print this page

        

*** 243,260 **** // Logger.global.manager will be null. // // In order to finish the initialization of the global logger, we // will therefore call LogManager.getLogManager() here. // ! // Care must be taken *not* to call Logger.getGlobal() in ! // LogManager static initializers in order to avoid such ! // deadlocks. ! // ! if (global != null && global.manager == null) { ! // Complete initialization of the global Logger. ! global.manager = LogManager.getLogManager(); ! } return global; } /** * The "global" Logger object is provided as a convenience to developers --- 243,272 ---- // Logger.global.manager will be null. // // In order to finish the initialization of the global logger, we // will therefore call LogManager.getLogManager() here. // ! // To prevent race conditions we also need to call ! // LogManager.getLogManager() unconditionally here. ! // Indeed we cannot rely on the observed value of global.manager, ! // because global.manager will become not null somewhere during ! // the initialization of LogManager. ! // If two threads are calling getGlobal() concurrently, one thread ! // will see global.manager null and call LogManager.getLogManager(), ! // but the other thread could come in at a time when global.manager ! // is already set although ensureLogManagerInitialized is not finished ! // yet... ! // Calling LogManager.getLogManager() unconditionally will fix that. ! ! LogManager.getLogManager(); ! ! // Now the global LogManager should be initialized, ! // and the global logger should have been added to ! // it, unless we were called within the constructor of a LogManager ! // subclass installed as LogManager, in which case global.manager ! // would still be null, and global will be lazily initialized later on. ! return global; } /** * The "global" Logger object is provided as a convenience to developers
*** 296,310 **** * of the messages require localization. * @throws MissingResourceException if the resourceBundleName is non-null and * no corresponding resource can be found. */ protected Logger(String name, String resourceBundleName) { ! this(name, resourceBundleName, null); } ! Logger(String name, String resourceBundleName, Class<?> caller) { ! this.manager = LogManager.getLogManager(); setupResourceInfo(resourceBundleName, caller); this.name = name; levelValue = Level.INFO.intValue(); } --- 308,322 ---- * of the messages require localization. * @throws MissingResourceException if the resourceBundleName is non-null and * no corresponding resource can be found. */ protected Logger(String name, String resourceBundleName) { ! this(name, resourceBundleName, null, LogManager.getLogManager()); } ! Logger(String name, String resourceBundleName, Class<?> caller, LogManager manager) { ! this.manager = manager; setupResourceInfo(resourceBundleName, caller); this.name = name; levelValue = Level.INFO.intValue(); }
*** 330,341 **** // The manager field is not initialized here. this.name = name; levelValue = Level.INFO.intValue(); } ! // It is called from the LogManager.<clinit> to complete ! // initialization of the global Logger. void setLogManager(LogManager manager) { this.manager = manager; } private void checkPermission() throws SecurityException { --- 342,353 ---- // The manager field is not initialized here. this.name = name; levelValue = Level.INFO.intValue(); } ! // It is called from LoggerContext.addLocalLogger() when the logger ! // is actually added to a LogManager. void setLogManager(LogManager manager) { this.manager = manager; } private void checkPermission() throws SecurityException {
*** 556,566 **** public static Logger getAnonymousLogger(String resourceBundleName) { LogManager manager = LogManager.getLogManager(); // cleanup some Loggers that have been GC'ed manager.drainLoggerRefQueueBounded(); Logger result = new Logger(null, resourceBundleName, ! Reflection.getCallerClass()); result.anonymous = true; Logger root = manager.getLogger(""); result.doSetParent(root); return result; } --- 568,578 ---- public static Logger getAnonymousLogger(String resourceBundleName) { LogManager manager = LogManager.getLogManager(); // cleanup some Loggers that have been GC'ed manager.drainLoggerRefQueueBounded(); Logger result = new Logger(null, resourceBundleName, ! Reflection.getCallerClass(), manager); result.anonymous = true; Logger root = manager.getLogger(""); result.doSetParent(root); return result; }
*** 1796,1806 **** */ public void setParent(Logger parent) { if (parent == null) { throw new NullPointerException(); } ! manager.checkPermission(); doSetParent(parent); } // Private method to do the work for parenting a child // Logger onto a parent logger. --- 1808,1818 ---- */ public void setParent(Logger parent) { if (parent == null) { throw new NullPointerException(); } ! checkPermission(); doSetParent(parent); } // Private method to do the work for parenting a child // Logger onto a parent logger.