< prev index next >

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

Print this page

        

@@ -351,11 +351,12 @@
         // notice that initializationDone is now true and return.
         // Otherwise - we have come here first! We will acquire the monitor,
         // see that initializationDone is still false, and perform the
         // initialization.
         //
-        synchronized(this) {
+        configurationLock.lock();
+        try {
             // If initializedCalled is true it means that we're already in
             // the process of initializing the LogManager in this thread.
             // There has been a recursive call to ensureLogManagerInitialized().
             final boolean isRecursiveInitialization = (initializedCalled == true);
 

@@ -376,10 +377,21 @@
             // Calling addLogger below will in turn call requiresDefaultLogger()
             // which will call ensureLogManagerInitialized().
             // We use initializedCalled to break the recursion.
             initializedCalled = true;
             try {
+//                // TODO: remove this before pushing
+//                // Hacky sleep that makes it possible to reproduce 8132550
+//                // consistently. see also reset().
+//                if (!(Thread.currentThread() instanceof Cleaner)) {
+//                    try {
+//                        // System.err.println("Initializing thread sleeping 2000L");
+//                        Thread.sleep(2000L);
+//                    } catch (InterruptedException ex) {
+//                        ex.printStackTrace();
+//                    }
+//                }
                 AccessController.doPrivileged(new PrivilegedAction<Object>() {
                     @Override
                     public Object run() {
                         assert rootLogger == null;
                         assert initializedCalled && !initializationDone;

@@ -407,10 +419,12 @@
                     }
                 });
             } finally {
                 initializationDone = true;
             }
+        } finally {
+            configurationLock.unlock();
         }
     }
 
     /**
      * Returns the global LogManager object.

@@ -421,40 +435,29 @@
             manager.ensureLogManagerInitialized();
         }
         return manager;
     }
 
-    private void readPrimordialConfiguration() {
-        if (!readPrimordialConfiguration) {
-            synchronized (this) {
+    private void readPrimordialConfiguration() { // must be called while holding configurationLock
                 if (!readPrimordialConfiguration) {
                     // If System.in/out/err are null, it's a good
                     // indication that we're still in the
                     // bootstrapping phase
                     if (System.out == null) {
                         return;
                     }
                     readPrimordialConfiguration = true;
-
                     try {
-                        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
-                                @Override
-                                public Void run() throws Exception {
                                     readConfiguration();
 
                                     // Platform loggers begin to delegate to java.util.logging.Logger
                                     sun.util.logging.PlatformLogger.redirectPlatformLoggers();
-                                    return null;
-                                }
-                            });
                     } catch (Exception ex) {
                         assert false : "Exception raised while reading logging configuration: " + ex;
                     }
                 }
             }
-        }
-    }
 
     // LoggerContext maps from AppContext
     private WeakHashMap<Object, LoggerContext> contextsMap = null;
 
     // Returns the LoggerContext for the user code (i.e. application or AppContext).

@@ -1326,10 +1329,23 @@
 
         // We don't want reset() and readConfiguration()
         // to run in parallel
         configurationLock.lock();
         try {
+
+//            // TODO: remove this before pushing
+//            // Hacky sleep that makes it possible to reproduce 8132550
+//            // consistently. see also ensureLogManagerInitialized().
+//            if (Thread.currentThread() instanceof Cleaner) {
+//                try {
+//                    // System.err.println("Cleaner Thread sleeping 5000L");
+//                    Thread.sleep(5000L);
+//                } catch (InterruptedException ex) {
+//                    ex.printStackTrace();
+//                }
+//            }
+
             // install new empty properties
             props = new Properties();
             // make sure we keep the loggers persistent until reset is done.
             // Those are the loggers for which we previously created a
             // handler from the configuration, and we need to prevent them
< prev index next >