Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/EventDispatchThread/EDTShutdownTest/EDTShutdownTest.java
38828 views
/*1* Copyright (c) 2014, 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 803169426@summary [macosx] TwentyThousandTest test intermittently hangs27@author Oleg Pekhovskiy28@run main EDTShutdownTest29*/3031import java.awt.EventQueue;32import java.awt.Toolkit;33import java.lang.reflect.InvocationTargetException;34import java.lang.reflect.Method;35import sun.awt.AWTAccessor;3637public class EDTShutdownTest {3839private static boolean passed = false;4041public static void main(String[] args) {42// Force EDT start with InvocationEvent43EventQueue.invokeLater(() -> {44// EventQueue is empty now45EventQueue queue = Toolkit.getDefaultToolkit()46.getSystemEventQueue();47Thread thread = AWTAccessor.getEventQueueAccessor()48.getDispatchThread(queue);49try {50/*51* Clear EventDispatchThread.doDispatch flag to break message52* loop in EventDispatchThread.pumpEventsForFilter()53*/54Method stopDispatching = thread.getClass()55.getDeclaredMethod("stopDispatching", null);56stopDispatching.setAccessible(true);57stopDispatching.invoke(thread, null);5859/*60* Post another InvocationEvent that must be handled by another61* instance of EDT62*/63EventQueue.invokeLater(() -> {64passed = true;65});66}67catch (InvocationTargetException | NoSuchMethodException68| IllegalAccessException e) {69}70});7172// Wait for EDT shutdown73EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();74Thread thread = AWTAccessor.getEventQueueAccessor()75.getDispatchThread(queue);76try {77thread.join();7879/*80* Wait for another EDT instance to handle the InvocationEvent81* and shutdown82*/83thread = AWTAccessor.getEventQueueAccessor()84.getDispatchThread(queue);85if (thread != null) {86thread.join();87}88}89catch (InterruptedException e) {90}9192if (passed) {93System.out.println("Test PASSED!");94}95else {96throw new RuntimeException("Test FAILED!");97}98}99}100101102