test/java/util/logging/LoggingDeadlock4.java

Print this page
rev 5551 : 8004928: TEST_BUG: Reduce dependence of CoreLib tests from the AWT subsystem
Summary: the tests were refactored to drop AWT dependence where it was possible.
Reviewed-by: alanb, mchung


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug     6977677
  27  * @summary Deadlock between LogManager.<clinit> and Logger.getLogger()
  28  * @author  Daniel D. Daugherty
  29  * @build LoggingDeadlock4
  30  * @run main/timeout=15 LoggingDeadlock4
  31  */
  32 
  33 import java.awt.Container;
  34 import java.util.concurrent.CountDownLatch;
  35 import java.util.logging.LogManager;
  36 import java.util.logging.Logger;
  37 
  38 public class LoggingDeadlock4 {
  39     private static CountDownLatch barrier      = new CountDownLatch(1);
  40     private static CountDownLatch lmIsRunning  = new CountDownLatch(1);
  41     private static CountDownLatch logIsRunning = new CountDownLatch(1);
  42 
  43     public static void main(String[] args) {
  44         System.out.println("main: LoggingDeadlock4 is starting.");
  45 
  46         // Loading the java.awt.Container class will create a
  47         // sun.util.logging.PlatformLogger$JavaLogger object
  48         // that has to be redirected when the LogManager class
  49         // is initialized. This can cause a deadlock between
  50         // LogManager.<clinit> and Logger.getLogger().
  51         try {
  52             Class.forName("java.awt.Container");
  53         } catch (ClassNotFoundException cnfe) {
  54             throw new RuntimeException("Test failed: could not load"
  55                 + " java.awt.Container." + cnfe);
  56         }
  57 



  58         Thread lmThread = new Thread("LogManagerThread") {
  59             public void run() {
  60                 // let main know LogManagerThread is running
  61                 lmIsRunning.countDown();
  62 
  63                 System.out.println(Thread.currentThread().getName()
  64                     + ": is running.");
  65 
  66                 try {
  67                     barrier.await();  // wait for race to start
  68                 } catch (InterruptedException e) {
  69                 }
  70 
  71                 LogManager manager = LogManager.getLogManager();
  72             }
  73         };
  74         lmThread.start();
  75 
  76         Thread logThread = new Thread("LoggerThread") {
  77             public void run() {




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug     6977677 8004928
  27  * @summary Deadlock between LogManager.<clinit> and Logger.getLogger()
  28  * @author  Daniel D. Daugherty
  29  * @compile -XDignore.symbol.file LoggingDeadlock4.java
  30  * @run main/othervm/timeout=15 LoggingDeadlock4
  31  */
  32 
  33 import java.awt.Container;
  34 import java.util.concurrent.CountDownLatch;
  35 import java.util.logging.LogManager;
  36 import java.util.logging.Logger;
  37 
  38 public class LoggingDeadlock4 {
  39     private static CountDownLatch barrier      = new CountDownLatch(1);
  40     private static CountDownLatch lmIsRunning  = new CountDownLatch(1);
  41     private static CountDownLatch logIsRunning = new CountDownLatch(1);
  42 
  43     // Create a sun.util.logging.PlatformLogger$JavaLogger object




  44     // that has to be redirected when the LogManager class
  45     // is initialized. This can cause a deadlock between
  46     // LogManager.<clinit> and Logger.getLogger().
  47     private static final sun.util.logging.PlatformLogger log =
  48         sun.util.logging.PlatformLogger.getLogger("java.util.logging");




  49 
  50     public static void main(String[] args) {
  51         System.out.println("main: LoggingDeadlock4 is starting.");
  52 
  53         Thread lmThread = new Thread("LogManagerThread") {
  54             public void run() {
  55                 // let main know LogManagerThread is running
  56                 lmIsRunning.countDown();
  57 
  58                 System.out.println(Thread.currentThread().getName()
  59                     + ": is running.");
  60 
  61                 try {
  62                     barrier.await();  // wait for race to start
  63                 } catch (InterruptedException e) {
  64                 }
  65 
  66                 LogManager manager = LogManager.getLogManager();
  67             }
  68         };
  69         lmThread.start();
  70 
  71         Thread logThread = new Thread("LoggerThread") {
  72             public void run() {