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/othervm/timeout=15 -Djava.awt.headless=true 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() {
78 // let main know LoggerThread is running
79 logIsRunning.countDown();
80
81 System.out.println(Thread.currentThread().getName()
82 + ": is running.");
83
84 try {
85 barrier.await(); // wait for race to start
86 } catch (InterruptedException e) {
87 }
88
89 Logger foo = Logger.getLogger("foo logger");
90 }
91 };
92 logThread.start();
93
94 try {
95 // wait for LogManagerThread and LoggerThread to get going
96 lmIsRunning.await();
97 logIsRunning.await();
98 } catch (InterruptedException e) {
99 }
100
101 barrier.countDown(); // start the race
102
103 try {
104 lmThread.join();
105 logThread.join();
106 } catch (InterruptedException ie) {
107 }
108
109 System.out.println("main: LoggingDeadlock4 is done.");
|
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/othervm/timeout=15 -Djava.awt.headless=true LoggingDeadlock4
31 */
32
33 import java.util.concurrent.CountDownLatch;
34 import java.util.logging.LogManager;
35 import java.util.logging.Logger;
36
37 public class LoggingDeadlock4 {
38 private static CountDownLatch barrier = new CountDownLatch(1);
39 private static CountDownLatch lmIsRunning = new CountDownLatch(1);
40 private static CountDownLatch logIsRunning = new CountDownLatch(1);
41
42 public static void main(String[] args) {
43 System.out.println("main: LoggingDeadlock4 is starting.");
44
45 // Loading the java.awt.Container class will create a
46 // sun.util.logging.PlatformLogger$JavaLogger object
47 // that has to be redirected when the LogManager class
48 // is initialized. This can cause a deadlock between
49 // LogManager.<clinit> and Logger.getLogger().
50 try {
51 Class.forName("java.awt.Container");
52 } catch (ClassNotFoundException cnfe) {
53 throw new RuntimeException("Test failed: could not load"
54 + " java.awt.Container." + cnfe);
55 }
56
57 Thread lmThread = new Thread("LogManagerThread") {
58 public void run() {
59 // let main know LogManagerThread is running
60 lmIsRunning.countDown();
61
62 System.out.println(Thread.currentThread().getName()
63 + ": is running.");
64
65 try {
66 barrier.await(); // wait for race to start
67 } catch (InterruptedException e) {
68 }
69
70 LogManager.getLogManager();
71 }
72 };
73 lmThread.start();
74
75 Thread logThread = new Thread("LoggerThread") {
76 public void run() {
77 // let main know LoggerThread is running
78 logIsRunning.countDown();
79
80 System.out.println(Thread.currentThread().getName()
81 + ": is running.");
82
83 try {
84 barrier.await(); // wait for race to start
85 } catch (InterruptedException e) {
86 }
87
88 Logger.getLogger("foo logger");
89 }
90 };
91 logThread.start();
92
93 try {
94 // wait for LogManagerThread and LoggerThread to get going
95 lmIsRunning.await();
96 logIsRunning.await();
97 } catch (InterruptedException e) {
98 }
99
100 barrier.countDown(); // start the race
101
102 try {
103 lmThread.join();
104 logThread.join();
105 } catch (InterruptedException ie) {
106 }
107
108 System.out.println("main: LoggingDeadlock4 is done.");
|