Path: blob/master/test/jdk/sun/awt/AppContext/8012933/Test8012933.java
41153 views
/*1* Copyright (c) 2013, 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*/2223/*24* @test25* @bug 801293326* @summary Tests (although somewhat indirectly) that createNewAppContext()27* immediately followed by dispose() works correctly28* @author Leonid Romanov29* @modules java.desktop/sun.awt30*/3132import sun.awt.SunToolkit;33import sun.awt.AppContext;3435public class Test8012933 {36private AppContext appContext = null;37final ThreadGroup threadGroup = new ThreadGroup("test thread group");38final Object lock = new Object();39boolean isCreated = false;4041public static void main(String[] args) throws Exception {42SunToolkit.createNewAppContext();43new Test8012933().test();44}4546private void test() throws Exception {47createAppContext();48long startTime = System.currentTimeMillis();49appContext.dispose();50long endTime = System.currentTimeMillis();5152// In case of the bug, calling dispose() when there is no EQ53// dispatch thread running fails to create it, so it takes54// almost 10 sec to return from dispose(), which is spent55// waiting on the notificationLock.56if ((endTime - startTime) > 9000) {57throw new RuntimeException("Returning from dispose() took too much time, probably a bug");58}59}6061private void createAppContext() {62isCreated = false;63final Runnable runnable = new Runnable() {64public void run() {65appContext = SunToolkit.createNewAppContext();66synchronized (lock) {67isCreated = true;68lock.notifyAll();69}70}71};7273final Thread thread = new Thread(threadGroup, runnable, "creates app context");74synchronized (lock) {75thread.start();76while (!isCreated) {77try {78lock.wait();79} catch (InterruptedException ie) {80ie.printStackTrace();81}82}83}8485if (appContext == null) {86throw new RuntimeException("failed to create app context.");87} else {88System.out.println("app context was created.");89}90}9192}939495