blob: 32332307f56d1b3faea541a8e0ddd94c326e984a [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
jeffhao5d1ac922011-09-29 17:41:15 -070016
17/**
18 * This causes most VMs to lock up.
19 *
20 * Interrupting threads in class initialization should NOT work.
21 */
22public class Main {
23 public static boolean aInitialized = false;
24 public static boolean bInitialized = false;
25
26 static public void main(String[] args) {
27 Thread thread1, thread2;
28
29 System.out.println("Deadlock test starting.");
30 thread1 = new Thread() { public void run() { new A(); } };
31 thread2 = new Thread() { public void run() { new B(); } };
32 thread1.start();
Elliott Hughes741b5b72012-01-31 19:18:51 -080033 // Give thread1 a chance to start before starting thread2.
34 try { Thread.sleep(1000); } catch (InterruptedException ie) { }
jeffhao5d1ac922011-09-29 17:41:15 -070035 thread2.start();
36
37 try { Thread.sleep(6000); } catch (InterruptedException ie) { }
38
Elliott Hughes741b5b72012-01-31 19:18:51 -080039 System.out.println("Deadlock test interrupting threads.");
jeffhao5d1ac922011-09-29 17:41:15 -070040 thread1.interrupt();
41 thread2.interrupt();
42 System.out.println("Deadlock test main thread bailing.");
43 System.out.println("A initialized: " + aInitialized);
44 System.out.println("B initialized: " + bInitialized);
45 System.exit(0);
46 }
47}
48
49class A {
50 static {
51 System.out.println("A initializing...");
52 try { Thread.sleep(3000); } catch (InterruptedException ie) { }
53 new B();
54 System.out.println("A initialized");
55 Main.aInitialized = true;
56 }
57}
58
59class B {
60 static {
61 System.out.println("B initializing...");
62 try { Thread.sleep(3000); } catch (InterruptedException ie) { }
63 new A();
64 System.out.println("B initialized");
65 Main.bInitialized = true;
66 }
67}