Andreas Gampe | 8f1fa10 | 2015-01-22 19:48:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | */ |
| 16 | |
| 17 | /** |
| 18 | * Test that daemon threads still contending for a lock don't make the runtime abort on shutdown. |
| 19 | */ |
| 20 | public class Main { |
| 21 | |
| 22 | public final static int THREAD_COUNT = 32; |
| 23 | |
| 24 | public static void main(String[] args) throws Exception { |
| 25 | Object sync = new Object(); |
| 26 | |
| 27 | for (int i = 0; i < THREAD_COUNT; i++) { |
| 28 | Thread t = new Thread(new Wait(sync)); |
| 29 | t.setDaemon(true); |
| 30 | t.start(); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | private static class Wait implements Runnable { |
| 35 | private Object obj; |
| 36 | |
| 37 | public Wait(Object obj) { |
| 38 | this.obj = obj; |
| 39 | } |
| 40 | |
| 41 | public void run() { |
| 42 | for (;;) { |
| 43 | synchronized(obj) { |
| 44 | try { |
| 45 | obj.wait(1); |
| 46 | } catch (Exception exc) { |
| 47 | exc.printStackTrace(System.out); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } |