1c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe/* 2c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * Copyright (C) 2015 The Android Open Source Project 3c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * 4c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * Licensed under the Apache License, Version 2.0 (the "License"); 5c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * you may not use this file except in compliance with the License. 6c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * You may obtain a copy of the License at 7c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * 8c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * http://www.apache.org/licenses/LICENSE-2.0 9c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * 10c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * Unless required by applicable law or agreed to in writing, software 11c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * distributed under the License is distributed on an "AS IS" BASIS, 12c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * See the License for the specific language governing permissions and 14c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * limitations under the License. 15c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe */ 16c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe 17c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe/** 18c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe * Test that daemon threads still contending for a lock don't make the runtime abort on shutdown. 19c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe */ 20c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampepublic class Main { 21c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe 22c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe public final static int THREAD_COUNT = 32; 23c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe 24c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe public static void main(String[] args) throws Exception { 25c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe Object sync = new Object(); 26c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe 27c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe for (int i = 0; i < THREAD_COUNT; i++) { 28c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe Thread t = new Thread(new Wait(sync)); 29c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe t.setDaemon(true); 30c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe t.start(); 31c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe } 32c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe } 33c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe 34c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe private static class Wait implements Runnable { 35c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe private Object obj; 36c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe 37c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe public Wait(Object obj) { 38c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe this.obj = obj; 39c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe } 40c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe 41c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe public void run() { 42c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe for (;;) { 43c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe synchronized(obj) { 44c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe try { 45c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe obj.wait(1); 46c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe } catch (Exception exc) { 47c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe exc.printStackTrace(System.out); 48c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe } 49c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe } 50c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe } 51c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe } 52c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe } 53c0440f69ebf051ff2ffdc00de51005a040014462Andreas Gampe} 54