Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
d2f2c8aa
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d2f2c8aa
编写于
2月 12, 2009
作者:
A
art
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6799345: JFC demos threw exception in the Java Console when applets are closed
Reviewed-by: alexp, peterz
上级
54547bea
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
234 addition
and
28 deletion
+234
-28
src/share/classes/javax/swing/SwingWorker.java
src/share/classes/javax/swing/SwingWorker.java
+24
-26
src/share/classes/javax/swing/TimerQueue.java
src/share/classes/javax/swing/TimerQueue.java
+7
-2
test/javax/swing/system/6799345/TestShutdown.java
test/javax/swing/system/6799345/TestShutdown.java
+203
-0
未找到文件。
src/share/classes/javax/swing/SwingWorker.java
浏览文件 @
d2f2c8aa
/*
/*
* Copyright 2005-200
6
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2005-200
9
Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -778,35 +778,33 @@ public abstract class SwingWorker<T, V> implements RunnableFuture<T> {
...
@@ -778,35 +778,33 @@ public abstract class SwingWorker<T, V> implements RunnableFuture<T> {
threadFactory
);
threadFactory
);
appContext
.
put
(
SwingWorker
.
class
,
executorService
);
appContext
.
put
(
SwingWorker
.
class
,
executorService
);
//register shutdown hook for this executor service
// Don't use ShutdownHook here as it's not enough. We should track
// AppContext disposal instead of JVM shutdown, see 6799345 for details
final
ExecutorService
es
=
executorService
;
final
ExecutorService
es
=
executorService
;
final
Runnable
shutdownHook
=
appContext
.
addPropertyChangeListener
(
AppContext
.
DISPOSED_PROPERTY_NAME
,
new
Runnable
()
{
new
PropertyChangeListener
()
{
final
WeakReference
<
ExecutorService
>
executorServiceRef
=
@Override
new
WeakReference
<
ExecutorService
>(
es
);
public
void
propertyChange
(
PropertyChangeEvent
pce
)
{
public
void
run
()
{
boolean
disposed
=
(
Boolean
)
pce
.
getNewValue
();
final
ExecutorService
executorService
=
if
(
disposed
)
{
executorServiceRef
.
get
();
final
WeakReference
<
ExecutorService
>
executorServiceRef
=
if
(
executorService
!=
null
)
{
new
WeakReference
<
ExecutorService
>(
es
);
AccessController
.
doPrivileged
(
final
ExecutorService
executorService
=
new
PrivilegedAction
<
Void
>()
{
executorServiceRef
.
get
();
public
Void
run
()
{
if
(
executorService
!=
null
)
{
executorService
.
shutdown
();
AccessController
.
doPrivileged
(
return
null
;
new
PrivilegedAction
<
Void
>()
{
public
Void
run
()
{
executorService
.
shutdown
();
return
null
;
}
}
}
});
);
}
}
}
}
}
};
}
);
AccessController
.
doPrivileged
(
new
PrivilegedAction
<
Void
>()
{
public
Void
run
()
{
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
shutdownHook
));
return
null
;
}
});
}
}
return
executorService
;
return
executorService
;
}
}
...
...
src/share/classes/javax/swing/TimerQueue.java
浏览文件 @
d2f2c8aa
/*
/*
* Copyright 1997-200
7
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1997-200
9
Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -191,7 +191,12 @@ class TimerQueue implements Runnable
...
@@ -191,7 +191,12 @@ class TimerQueue implements Runnable
}
finally
{
}
finally
{
timer
.
getLock
().
unlock
();
timer
.
getLock
().
unlock
();
}
}
}
catch
(
InterruptedException
ignore
)
{
}
catch
(
InterruptedException
ie
)
{
// Shouldn't ignore InterruptedExceptions here, so AppContext
// is disposed gracefully, see 6799345 for details
if
(
AppContext
.
getAppContext
().
isDisposed
())
{
break
;
}
}
}
}
}
}
}
...
...
test/javax/swing/system/6799345/TestShutdown.java
0 → 100644
浏览文件 @
d2f2c8aa
/*
* 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 6799345
@summary Tests that no exceptions are thrown from TimerQueue and
SwingWorker on AppContext shutdown
@author art
@run main TestShutdown
*/
import
java.awt.*
;
import
java.awt.event.*
;
import
java.util.*
;
import
javax.swing.*
;
import
sun.awt.*
;
public
class
TestShutdown
{
private
static
AppContext
targetAppContext
;
private
static
JFrame
f
;
private
static
JTextField
tf
;
private
static
volatile
boolean
exceptionsOccurred
=
false
;
private
static
volatile
boolean
appcontextInitDone
=
false
;
private
static
int
timerValue
=
0
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
ThreadGroup
tg
=
new
TestThreadGroup
(
"TTG"
);
Thread
t
=
new
Thread
(
tg
,
new
TestRunnable
(),
"InitThread"
);
t
.
start
();
while
(!
appcontextInitDone
)
{
Thread
.
sleep
(
500
);
}
targetAppContext
.
dispose
();
if
(
exceptionsOccurred
)
{
throw
new
RuntimeException
(
"Test FAILED: some exceptions occurred"
);
}
}
static
void
initGUI
()
{
f
=
new
JFrame
(
"F"
);
f
.
setBounds
(
100
,
100
,
200
,
100
);
tf
=
new
JTextField
(
"Test"
);
f
.
add
(
tf
);
f
.
setVisible
(
true
);
}
static
void
startGUI
()
{
// caret blink Timer
tf
.
requestFocusInWindow
();
// misc Timer
ActionListener
al
=
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
ae
)
{
System
.
out
.
println
(
"Timer tick: "
+
timerValue
++);
}
};
new
javax
.
swing
.
Timer
(
30
,
al
).
start
();
}
static
class
TestThreadGroup
extends
ThreadGroup
{
public
TestThreadGroup
(
String
name
)
{
super
(
name
);
}
@Override
public
synchronized
void
uncaughtException
(
Thread
thread
,
Throwable
t
)
{
if
(
t
instanceof
ThreadDeath
)
{
// this one is expected, rethrow
throw
(
ThreadDeath
)
t
;
}
System
.
err
.
println
(
"Test FAILED: an exception is caught in the "
+
"target thread group on thread "
+
thread
.
getName
());
t
.
printStackTrace
(
System
.
err
);
exceptionsOccurred
=
true
;
}
}
static
class
TestRunnable
implements
Runnable
{
@Override
public
void
run
()
{
SunToolkit
stk
=
(
SunToolkit
)
Toolkit
.
getDefaultToolkit
();
targetAppContext
=
stk
.
createNewAppContext
();
// create and show frame and text field
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
@Override
public
void
run
()
{
initGUI
();
}
});
stk
.
realSync
();
// start some Timers
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
@Override
public
void
run
()
{
startGUI
();
}
});
stk
.
realSync
();
// start multiple SwingWorkers
while
(!
Thread
.
interrupted
())
{
try
{
new
TestSwingWorker
().
execute
();
Thread
.
sleep
(
40
);
}
catch
(
Exception
e
)
{
// exception here is expected, skip
break
;
}
}
}
}
static
class
TestSwingWorker
extends
SwingWorker
<
String
,
Integer
>
{
@Override
public
String
doInBackground
()
{
Random
r
=
new
Random
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
try
{
int
delay
=
r
.
nextInt
()
%
50
;
Thread
.
sleep
(
delay
);
publish
(
delay
);
}
catch
(
Exception
z
)
{
break
;
}
}
if
(!
appcontextInitDone
)
{
appcontextInitDone
=
true
;
}
return
"Done"
;
}
@Override
public
void
process
(
java
.
util
.
List
<
Integer
>
chunks
)
{
for
(
Integer
i
:
chunks
)
{
System
.
err
.
println
(
"Processed: "
+
i
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录