Main.java revision 2ad60cfc28e14ee8f0bb038720836a4696c478ad
1// Copyright 2006 The Android Open Source Project
2
3/**
4 * This causes most VMs to lock up.
5 *
6 * Interrupting threads in class initialization should NOT work.
7 */
8public class Main {
9    public static boolean aInitialized = false;
10    public static boolean bInitialized = false;
11
12    static public void main(String[] args) {
13        Thread thread1, thread2;
14
15        System.out.println("Deadlock test starting.");
16        thread1 = new Thread() { public void run() { new A(); } };
17        thread2 = new Thread() { public void run() { new B(); } };
18        thread1.start();
19        thread2.start();
20
21        try { Thread.sleep(6000); } catch (InterruptedException ie) { }
22
23        System.out.println("Deadlock test interupting threads.");
24        thread1.interrupt();
25        thread2.interrupt();
26        System.out.println("Deadlock test main thread bailing.");
27        System.out.println("A initialized: " + aInitialized);
28        System.out.println("B initialized: " + bInitialized);
29        System.exit(0);
30    }
31}
32
33class A {
34    static {
35        System.out.println("A initializing...");
36        try { Thread.sleep(3000); } catch (InterruptedException ie) { }
37        new B();
38        System.out.println("A initialized");
39        Main.aInitialized = true;
40    }
41}
42
43class B {
44    static {
45        System.out.println("B initializing...");
46        try { Thread.sleep(3000); } catch (InterruptedException ie) { }
47        new A();
48        System.out.println("B initialized");
49        Main.bInitialized = true;
50    }
51}
52
53