blob: e4ee9aeec0227b0f37b5c93f0dd0f99f7f397dfd [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();
33 thread2.start();
34
35 try { Thread.sleep(6000); } catch (InterruptedException ie) { }
36
37 System.out.println("Deadlock test interupting threads.");
38 thread1.interrupt();
39 thread2.interrupt();
40 System.out.println("Deadlock test main thread bailing.");
41 System.out.println("A initialized: " + aInitialized);
42 System.out.println("B initialized: " + bInitialized);
43 System.exit(0);
44 }
45}
46
47class A {
48 static {
49 System.out.println("A initializing...");
50 try { Thread.sleep(3000); } catch (InterruptedException ie) { }
51 new B();
52 System.out.println("A initialized");
53 Main.aInitialized = true;
54 }
55}
56
57class B {
58 static {
59 System.out.println("B initializing...");
60 try { Thread.sleep(3000); } catch (InterruptedException ie) { }
61 new A();
62 System.out.println("B initialized");
63 Main.bInitialized = true;
64 }
65}