01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.drlvm.tests.regression.h4706;
19:
20: /**
21: * Checks that interruption of several threads doesn't cause VM crash due to
22: * race condition in thread manager implementation for thread interrupting.
23: * First main thread creates and starts a number of test threads.
24: * Second main thead interrupts all of the test threads.
25: * Each of the test threads waits on the same monitor.
26: */
27: public class ThreadArrayInterrupt {
28:
29: static final int threadNum = 32;
30: static Object barrier = new Object();
31:
32: public static void main(String[] args) {
33: Thread[] threads = new Thread[threadNum];
34:
35: synchronized (barrier) {
36: System.out.println("starting threads...");
37:
38: for (int i = 0; i < threadNum; i++) {
39: threads[i] = new TestThread("Thread-" + i);
40: threads[i].start();
41: }
42:
43: System.out.println("all threads started");
44: }
45:
46: System.out.println("Interrupting all threads...");
47:
48: for (int i = 0; i < threadNum; i++) {
49: threads[i].interrupt();
50: }
51: }
52:
53: static class TestThread extends Thread {
54:
55: TestThread(String name) {
56: super (name);
57: }
58:
59: public void run() {
60: synchronized (barrier) {
61: try {
62: barrier.wait();
63: } catch (InterruptedException e) {
64: System.out.println("Interrupted: " + getName());
65: }
66: }
67: }
68: }
69: }
|