Path: blob/master/test/jdk/java/awt/EventQueue/PushPopDeadlock2/PushPopTest.java
41153 views
/*1* Copyright (c) 2009, 2016, 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@key headful26@bug 491332427@author Oleg Sukhodolsky: area=eventqueue28@modules java.desktop/sun.awt29@run main/timeout=30 PushPopTest30*/3132import java.awt.*;33import java.awt.event.*;34import java.util.EmptyStackException;35import sun.awt.SunToolkit;3637public class PushPopTest {3839public static Frame frame;40public static void main(String[] args) {41frame = new Frame("");42frame.pack();4344Runnable dummy = new Runnable() {45public void run() {46System.err.println("Dummy is here.");47System.err.flush();48}49};50EventQueue seq = Toolkit.getDefaultToolkit().getSystemEventQueue();51MyEventQueue1 eq1 = new MyEventQueue1();52MyEventQueue2 eq2 = new MyEventQueue2();53EventQueue.invokeLater(dummy);5455seq.push(eq1);56EventQueue.invokeLater(dummy);5758eq1.push(eq2);59EventQueue.invokeLater(dummy);60Runnable runnable = new Runnable() {61public void run() {62System.err.println("Dummy from SunToolkit");63System.err.flush();64}65};66InvocationEvent ie = new InvocationEvent(eq2, runnable, null, false);67// System.err.println(ie);68SunToolkit.postEvent(SunToolkit.targetToAppContext(frame), ie);69eq1.pop();70frame.dispose();71}72}7374class MyEventQueue1 extends EventQueue {7576public void pop() {77super.pop();78}79}8081class MyEventQueue2 extends EventQueue {8283protected void pop() {84System.err.println("pop2()");85Thread.dumpStack();86try {87EventQueue.invokeAndWait(new Runnable() {88public void run() {89Runnable runnable = new Runnable() {90public void run() {91System.err.println("Dummy from pop");92System.err.flush();93}94};95InvocationEvent ie = new InvocationEvent(MyEventQueue2.this, runnable, null, false);96SunToolkit.postEvent(SunToolkit.targetToAppContext(PushPopTest.frame), ie);97postEvent(ie);98}99});100} catch (InterruptedException ie) {101ie.printStackTrace();102} catch (java.lang.reflect.InvocationTargetException ie) {103ie.printStackTrace();104}105super.pop();106}107}108109110