ApplicationThreadsStop.java revision 14851:980da45565c8
1/* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24import java.awt.AWTException; 25import java.awt.Frame; 26import java.awt.Robot; 27 28import sun.awt.AppContext; 29import sun.awt.SunToolkit; 30 31/** 32 * @test 33 * @key headful 34 * @bug 8136858 35 * @modules java.desktop/sun.awt 36 * @run main/othervm/java.security.policy=java.policy -Djava.security.manager ApplicationThreadsStop 37 */ 38public final class ApplicationThreadsStop implements Runnable { 39 40 private static AppContext contextToDispose; 41 private static Thread thread; 42 43 public static void main(final String[] args) throws Exception { 44 ThreadGroup tg = new ThreadGroup("TestThreadGroup"); 45 Thread t = new Thread(tg, new ApplicationThreadsStop()); 46 t.start(); 47 t.join(); 48 contextToDispose.dispose(); 49 // wait for appcontext to be destroyed 50 Thread.sleep(10000); 51 if(thread.isAlive()){ 52 throw new RuntimeException("Thread is alive"); 53 } 54 } 55 56 @Override 57 public void run() { 58 contextToDispose = SunToolkit.createNewAppContext(); 59 Frame f = new Frame(); 60 f.setSize(300, 300); 61 f.setLocationRelativeTo(null); 62 f.setVisible(true); 63 thread = new Thread(() -> { 64 while(true); 65 }); 66 thread.start(); 67 sync(); 68 } 69 70 private static void sync() { 71 try { 72 new Robot().waitForIdle(); 73 } catch (AWTException e) { 74 throw new RuntimeException(e); 75 } 76 } 77} 78