Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/EventQueue/PushPopDeadlock2/PushPopTest.java
38828 views
/*1* Copyright (c) 2009, 2010, 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 491332426@author Oleg Sukhodolsky: area=eventqueue27@run main/timeout=30 PushPopTest28*/2930import java.awt.*;31import java.awt.event.*;32import java.util.EmptyStackException;33import sun.awt.SunToolkit;3435public class PushPopTest {3637public static Frame frame;38public static void main(String[] args) {39frame = new Frame("");40frame.pack();4142Runnable dummy = new Runnable() {43public void run() {44System.err.println("Dummy is here.");45System.err.flush();46}47};48EventQueue seq = Toolkit.getDefaultToolkit().getSystemEventQueue();49MyEventQueue1 eq1 = new MyEventQueue1();50MyEventQueue2 eq2 = new MyEventQueue2();51EventQueue.invokeLater(dummy);5253seq.push(eq1);54EventQueue.invokeLater(dummy);5556eq1.push(eq2);57EventQueue.invokeLater(dummy);58Runnable runnable = new Runnable() {59public void run() {60System.err.println("Dummy from SunToolkit");61System.err.flush();62}63};64InvocationEvent ie = new InvocationEvent(eq2, runnable, null, false);65// System.err.println(ie);66SunToolkit.postEvent(SunToolkit.targetToAppContext(frame), ie);67eq1.pop();68frame.dispose();69}70}7172class MyEventQueue1 extends EventQueue {7374public void pop() {75super.pop();76}77}7879class MyEventQueue2 extends EventQueue {8081protected void pop() {82System.err.println("pop2()");83Thread.dumpStack();84try {85EventQueue.invokeAndWait(new Runnable() {86public void run() {87Runnable runnable = new Runnable() {88public void run() {89System.err.println("Dummy from pop");90System.err.flush();91}92};93InvocationEvent ie = new InvocationEvent(MyEventQueue2.this, runnable, null, false);94SunToolkit.postEvent(SunToolkit.targetToAppContext(PushPopTest.frame), ie);95postEvent(ie);96}97});98} catch (InterruptedException ie) {99ie.printStackTrace();100} catch (java.lang.reflect.InvocationTargetException ie) {101ie.printStackTrace();102}103super.pop();104}105}106107108