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 */ 8 public class Main { 9 public static boolean aInitialized = false; 10 public static boolean bInitialized = false; 11 main(String[] args)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 // Give thread1 a chance to start before starting thread2. 20 try { Thread.sleep(1000); } catch (InterruptedException ie) { } 21 thread2.start(); 22 23 try { Thread.sleep(6000); } catch (InterruptedException ie) { } 24 25 System.out.println("Deadlock test interrupting threads."); 26 thread1.interrupt(); 27 thread2.interrupt(); 28 System.out.println("Deadlock test main thread bailing."); 29 System.out.println("A initialized: " + aInitialized); 30 System.out.println("B initialized: " + bInitialized); 31 System.exit(0); 32 } 33 } 34 35 class A { 36 static { 37 System.out.println("A initializing..."); 38 try { Thread.sleep(3000); } catch (InterruptedException ie) { } B()39 new B(); 40 System.out.println("A initialized"); 41 Main.aInitialized = true; 42 } 43 } 44 45 class B { 46 static { 47 System.out.println("B initializing..."); 48 try { Thread.sleep(3000); } catch (InterruptedException ie) { } A()49 new A(); 50 System.out.println("B initialized"); 51 Main.bInitialized = true; 52 } 53 } 54