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