Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell11
提交
6732b96c
D
dragonwell11
项目概览
openanolis
/
dragonwell11
通知
7
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell11
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6732b96c
编写于
11月 27, 2009
作者:
A
art
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
4913324: Deadlock when using two event queues
Reviewed-by: anthony, ant, dcherepanov
上级
6c6a996e
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
359 addition
and
165 deletion
+359
-165
jdk/src/share/classes/java/awt/EventDispatchThread.java
jdk/src/share/classes/java/awt/EventDispatchThread.java
+3
-34
jdk/src/share/classes/java/awt/EventQueue.java
jdk/src/share/classes/java/awt/EventQueue.java
+230
-119
jdk/src/share/classes/sun/awt/AWTAccessor.java
jdk/src/share/classes/sun/awt/AWTAccessor.java
+4
-4
jdk/src/share/classes/sun/awt/AppContext.java
jdk/src/share/classes/sun/awt/AppContext.java
+18
-1
jdk/src/share/classes/sun/awt/SunToolkit.java
jdk/src/share/classes/sun/awt/SunToolkit.java
+1
-7
jdk/test/java/awt/EventQueue/PushPopDeadlock2/PushPopTest.java
...est/java/awt/EventQueue/PushPopDeadlock2/PushPopTest.java
+103
-0
未找到文件。
jdk/src/share/classes/java/awt/EventDispatchThread.java
浏览文件 @
6732b96c
...
...
@@ -104,11 +104,8 @@ class EventDispatchThread extends Thread {
}
else
{
stopEvent
.
dispatch
();
}
synchronized
(
theQueue
)
{
if
(
theQueue
.
getDispatchThread
()
==
this
)
{
theQueue
.
detachDispatchThread
();
}
}
theQueue
.
detachDispatchThread
(
this
,
false
);
}
public
void
stopDispatching
()
{
...
...
@@ -142,35 +139,7 @@ class EventDispatchThread extends Thread {
}
});
}
finally
{
/*
* This synchronized block is to secure that the event dispatch
* thread won't die in the middle of posting a new event to the
* associated event queue. It is important because we notify
* that the event dispatch thread is busy after posting a new event
* to its queue, so the EventQueue.dispatchThread reference must
* be valid at that point.
*/
synchronized
(
theQueue
)
{
if
(
theQueue
.
getDispatchThread
()
==
this
)
{
theQueue
.
detachDispatchThread
();
}
/*
* Event dispatch thread dies in case of an uncaught exception.
* A new event dispatch thread for this queue will be started
* only if a new event is posted to it. In case if no more
* events are posted after this thread died all events that
* currently are in the queue will never be dispatched.
*/
/*
* Fix for 4648733. Check both the associated java event
* queue and the PostEventQueue.
*/
if
(
theQueue
.
peekEvent
()
!=
null
||
!
SunToolkit
.
isPostEventQueueEmpty
())
{
theQueue
.
initDispatchThread
();
}
AWTAutoShutdown
.
getInstance
().
notifyThreadFree
(
this
);
}
theQueue
.
detachDispatchThread
(
this
,
true
);
}
}
...
...
jdk/src/share/classes/java/awt/EventQueue.java
浏览文件 @
6732b96c
此差异已折叠。
点击以展开。
jdk/src/share/classes/sun/awt/AWTAccessor.java
浏览文件 @
6732b96c
...
...
@@ -248,14 +248,14 @@ public final class AWTAccessor {
* An accessor for the EventQueue class
*/
public
interface
EventQueueAccessor
{
/*
* Gets the next event queue.
*/
EventQueue
getNextQueue
(
EventQueue
eventQueue
);
/*
* Gets the event dispatch thread.
*/
Thread
getDispatchThread
(
EventQueue
eventQueue
);
/*
* Checks if the current thread is EDT for the given EQ.
*/
public
boolean
isDispatchThreadImpl
(
EventQueue
eventQueue
);
}
/*
...
...
jdk/src/share/classes/sun/awt/AppContext.java
浏览文件 @
6732b96c
...
...
@@ -43,6 +43,9 @@ import java.util.HashSet;
import
java.beans.PropertyChangeSupport
;
import
java.beans.PropertyChangeListener
;
import
sun.util.logging.PlatformLogger
;
import
java.util.concurrent.locks.Condition
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.ReentrantLock
;
/**
* The AppContext is a table referenced by ThreadGroup which stores
...
...
@@ -132,10 +135,17 @@ public final class AppContext {
/* Since the contents of an AppContext are unique to each Java
* session, this class should never be serialized. */
/* The key to put()/get() the Java EventQueue into/from the AppContext.
/*
* The key to put()/get() the Java EventQueue into/from the AppContext.
*/
public
static
final
Object
EVENT_QUEUE_KEY
=
new
StringBuffer
(
"EventQueue"
);
/*
* The keys to store EventQueue push/pop lock and condition.
*/
public
final
static
Object
EVENT_QUEUE_LOCK_KEY
=
new
StringBuilder
(
"EventQueue.Lock"
);
public
final
static
Object
EVENT_QUEUE_COND_KEY
=
new
StringBuilder
(
"EventQueue.Condition"
);
/* A map of AppContexts, referenced by ThreadGroup.
*/
private
static
final
Map
<
ThreadGroup
,
AppContext
>
threadGroup2appContext
=
...
...
@@ -244,6 +254,13 @@ public final class AppContext {
return
Thread
.
currentThread
().
getContextClassLoader
();
}
});
// Initialize push/pop lock and its condition to be used by all the
// EventQueues within this AppContext
Lock
eventQueuePushPopLock
=
new
ReentrantLock
();
put
(
EVENT_QUEUE_LOCK_KEY
,
eventQueuePushPopLock
);
Condition
eventQueuePushPopCond
=
eventQueuePushPopLock
.
newCondition
();
put
(
EVENT_QUEUE_COND_KEY
,
eventQueuePushPopCond
);
}
private
static
final
ThreadLocal
<
AppContext
>
threadAppContext
=
...
...
jdk/src/share/classes/sun/awt/SunToolkit.java
浏览文件 @
6732b96c
...
...
@@ -722,13 +722,7 @@ public abstract class SunToolkit extends Toolkit
EventQueue
eq
=
(
EventQueue
)
appContext
.
get
(
AppContext
.
EVENT_QUEUE_KEY
);
AWTAccessor
.
EventQueueAccessor
accessor
=
AWTAccessor
.
getEventQueueAccessor
();
EventQueue
next
=
accessor
.
getNextQueue
(
eq
);
while
(
next
!=
null
)
{
eq
=
next
;
next
=
accessor
.
getNextQueue
(
eq
);
}
return
(
Thread
.
currentThread
()
==
accessor
.
getDispatchThread
(
eq
));
return
accessor
.
isDispatchThreadImpl
(
eq
);
}
public
Dimension
getScreenSize
()
{
...
...
jdk/test/java/awt/EventQueue/PushPopDeadlock2/PushPopTest.java
0 → 100644
浏览文件 @
6732b96c
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test
@bug 4913324
@author Oleg Sukhodolsky: area=eventqueue
@run main/timeout=30 PushPopTest
*/
import
java.awt.*
;
import
java.awt.event.*
;
import
java.util.EmptyStackException
;
import
sun.awt.SunToolkit
;
public
class
PushPopTest
{
public
static
Frame
frame
;
public
static
void
main
(
String
[]
args
)
{
frame
=
new
Frame
(
""
);
frame
.
pack
();
Runnable
dummy
=
new
Runnable
()
{
public
void
run
()
{
System
.
err
.
println
(
"Dummy is here."
);
}
};
EventQueue
seq
=
Toolkit
.
getDefaultToolkit
().
getSystemEventQueue
();
MyEventQueue1
eq1
=
new
MyEventQueue1
();
MyEventQueue2
eq2
=
new
MyEventQueue2
();
EventQueue
.
invokeLater
(
dummy
);
seq
.
push
(
eq1
);
EventQueue
.
invokeLater
(
dummy
);
eq1
.
push
(
eq2
);
EventQueue
.
invokeLater
(
dummy
);
Runnable
runnable
=
new
Runnable
()
{
public
void
run
()
{
System
.
err
.
println
(
"Dummy from SunToolkit"
);
}
};
InvocationEvent
ie
=
new
InvocationEvent
(
eq2
,
runnable
,
null
,
false
);
System
.
err
.
println
(
ie
);
SunToolkit
.
postEvent
(
SunToolkit
.
targetToAppContext
(
frame
),
ie
);
eq1
.
pop
();
frame
.
dispose
();
}
}
class
MyEventQueue1
extends
EventQueue
{
public
void
pop
()
throws
EmptyStackException
{
super
.
pop
();
}
}
class
MyEventQueue2
extends
EventQueue
{
protected
void
pop
()
throws
EmptyStackException
{
System
.
err
.
println
(
"pop2()"
);
Thread
.
dumpStack
();
try
{
EventQueue
.
invokeAndWait
(
new
Runnable
()
{
public
void
run
()
{
Runnable
runnable
=
new
Runnable
()
{
public
void
run
()
{
System
.
err
.
println
(
"Dummy from here"
);
}
};
InvocationEvent
ie
=
new
InvocationEvent
(
MyEventQueue2
.
this
,
runnable
,
null
,
false
);
SunToolkit
.
postEvent
(
SunToolkit
.
targetToAppContext
(
PushPopTest
.
frame
),
ie
);
postEvent
(
ie
);
}
});
}
catch
(
InterruptedException
ie
)
{
ie
.
printStackTrace
();
}
catch
(
java
.
lang
.
reflect
.
InvocationTargetException
ie
)
{
ie
.
printStackTrace
();
}
super
.
pop
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录