1/* 2 * Copyright (c) 2011, 2012, 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. 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 6487638 7041595 27 * @summary Calling LogManager.addLogger() and Logger.getLogger() cause deadlock 28 * @author Serguei Spitsyn 29 * @build LoggingDeadlock3 30 * @run main/timeout=80 LoggingDeadlock3 31 */ 32 33import java.io.*; 34import java.util.logging.LogManager; 35import java.util.logging.Logger; 36 37public class LoggingDeadlock3 { 38 static final int ITER_CNT = 50000; 39 static final String MSG_PASSED = "LoggingDeadlock3: passed"; 40 static final LogManager logMgr = LogManager.getLogManager(); 41 static final PrintStream out = System.out; 42 43 public static void main(String args[]) throws Exception { 44 String tstSrc = System.getProperty("test.src"); 45 File fname = new File(tstSrc, "LoggingDeadlock3.props"); 46 String prop = fname.getCanonicalPath(); 47 System.setProperty("java.util.logging.config.file", prop); 48 logMgr.readConfiguration(); 49 50 Thread t1 = new Thread(new AddLogger()); 51 Thread t2 = new Thread(new GetLogger()); 52 t1.start(); t2.start(); 53 t1.join(); t2.join(); 54 out.println("\n" + MSG_PASSED); 55 } 56 57 public static class MyLogger extends Logger { 58 protected MyLogger(String name) { super(name, null); } 59 } 60 61 public static class GetLogger implements Runnable { 62 public void run() { 63 for (int cnt = 0; cnt < ITER_CNT * 8; cnt++) { 64 Logger.getLogger("com.sun.Hello"+cnt/10); 65 if (cnt % 1000 == 0) out.print("1"); 66 if (cnt % 10000 == 0) out.println(); 67 } 68 } 69 } 70 71 public static class AddLogger implements Runnable { 72 public void run() { 73 for (int cnt = 0; cnt < ITER_CNT; cnt++) { 74 Logger addLogger = new MyLogger("com.sun.Hello"+cnt); 75 logMgr.addLogger(addLogger); 76 if (cnt % 100 == 0) out.print("2"); 77 if (cnt % 1000 == 0) out.println(); 78 } 79 } 80 } 81} 82