1 /* 2 * Copyright (c) 2014, 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 24 /* 25 @test 26 @bug 8031694 27 @summary [macosx] TwentyThousandTest test intermittently hangs 28 @author Oleg Pekhovskiy 29 @modules java.desktop/sun.awt 30 @run main EDTShutdownTest 31 */ 32 33 import java.awt.EventQueue; 34 import java.awt.Toolkit; 35 import java.lang.reflect.InvocationTargetException; 36 import java.lang.reflect.Method; 37 import sun.awt.AWTAccessor; 38 39 public class EDTShutdownTest { 40 41 private static boolean passed = false; 42 43 public static void main(String[] args) { 44 // Force EDT start with InvocationEvent 45 EventQueue.invokeLater(() -> { 46 // EventQueue is empty now 47 EventQueue queue = Toolkit.getDefaultToolkit() 48 .getSystemEventQueue(); 49 Thread thread = AWTAccessor.getEventQueueAccessor() 50 .getDispatchThread(queue); 51 try { 52 /* 53 * Clear EventDispatchThread.doDispatch flag to break message 54 * loop in EventDispatchThread.pumpEventsForFilter() 55 */ 56 Method stopDispatching = thread.getClass() 57 .getDeclaredMethod("stopDispatching", null); 58 stopDispatching.setAccessible(true); 59 stopDispatching.invoke(thread, null); 60 61 /* 62 * Post another InvocationEvent that must be handled by another 63 * instance of EDT 64 */ 65 EventQueue.invokeLater(() -> { 66 passed = true; 67 }); 68 } 69 catch (InvocationTargetException | NoSuchMethodException 70 | IllegalAccessException e) { 71 } 72 }); 73 74 // Wait for EDT shutdown 75 EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); 76 Thread thread = AWTAccessor.getEventQueueAccessor() 77 .getDispatchThread(queue); 78 try { 79 thread.join(); 80 81 /* 82 * Wait for another EDT instance to handle the InvocationEvent 83 * and shutdown 84 */ 85 thread = AWTAccessor.getEventQueueAccessor() 86 .getDispatchThread(queue); 87 if (thread != null) { 88 thread.join(); 89 } 90 } 91 catch (InterruptedException e) { 92 } 93 94 if (passed) { 95 System.out.println("Test PASSED!"); 96 } 97 else { 98 throw new RuntimeException("Test FAILED!"); 99 } 100 } 101 }