Path: blob/master/test/jdk/java/awt/AppContext/ApplicationThreadsStop/ApplicationThreadsStop.java
41155 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.AWTException;24import java.awt.Frame;25import java.awt.Robot;2627import sun.awt.AppContext;28import sun.awt.SunToolkit;2930/**31* @test32* @key headful33* @bug 813685834* @modules java.desktop/sun.awt35* @run main/othervm/java.security.policy=java.policy -Djava.security.manager ApplicationThreadsStop36*/37public final class ApplicationThreadsStop implements Runnable {3839private static AppContext contextToDispose;40private static Thread thread;4142public static void main(final String[] args) throws Exception {43ThreadGroup tg = new ThreadGroup("TestThreadGroup");44Thread t = new Thread(tg, new ApplicationThreadsStop());45t.start();46t.join();47contextToDispose.dispose();48// wait for appcontext to be destroyed49Thread.sleep(10000);50if(thread.isAlive()){51throw new RuntimeException("Thread is alive");52}53}5455@Override56public void run() {57contextToDispose = SunToolkit.createNewAppContext();58Frame f = new Frame();59f.setSize(300, 300);60f.setLocationRelativeTo(null);61f.setVisible(true);62thread = new Thread(() -> {63while(true);64});65thread.start();66sync();67}6869private static void sync() {70try {71new Robot().waitForIdle();72} catch (AWTException e) {73throw new RuntimeException(e);74}75}76}777879