Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/awt/AppContext/8012933/Test8012933.java
38918 views
/*1* Copyright (c) 2013, 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*/3031import sun.awt.SunToolkit;32import sun.awt.AppContext;3334public class Test8012933 {35private AppContext appContext = null;36final ThreadGroup threadGroup = new ThreadGroup("test thread group");37final Object lock = new Object();38boolean isCreated = false;3940public static void main(String[] args) throws Exception {41SunToolkit.createNewAppContext();42new Test8012933().test();43}4445private void test() throws Exception {46createAppContext();47long startTime = System.currentTimeMillis();48appContext.dispose();49long endTime = System.currentTimeMillis();5051// In case of the bug, calling dispose() when there is no EQ52// dispatch thread running fails to create it, so it takes53// almost 10 sec to return from dispose(), which is spent54// waiting on the notificationLock.55if ((endTime - startTime) > 9000) {56throw new RuntimeException("Returning from dispose() took too much time, probably a bug");57}58}5960private void createAppContext() {61isCreated = false;62final Runnable runnable = new Runnable() {63public void run() {64appContext = SunToolkit.createNewAppContext();65synchronized (lock) {66isCreated = true;67lock.notifyAll();68}69}70};7172final Thread thread = new Thread(threadGroup, runnable, "creates app context");73synchronized (lock) {74thread.start();75while (!isCreated) {76try {77lock.wait();78} catch (InterruptedException ie) {79ie.printStackTrace();80}81}82}8384if (appContext == null) {85throw new RuntimeException("failed to create app context.");86} else {87System.out.println("app context was created.");88}89}9091}929394