【发布时间】:2014-06-08 00:07:47
【问题描述】:
我正在尝试中断一个正常运行的线程(它不处于 sleep() 或 wait() 状态)。
在网络中进行时,我知道中断正常运行的线程只会将标志设置为 true 并继续该过程。
代码sn-p是
one.java
......
......
actionperformedmethod {
if (actionCmd.equals("cancel")) {
try {
r1.stop(); // to two.java
} catch (InterruptedException ex) {
....
....
}
}
}
在two.java
.....
.....
stop method() throws InterruptedException{
if(!(t.isInterrupted())){
t.interrupt();
throw new InterruptedException();
}
}
从 two.java 当我抛出 InterruptedException 时,我可以在 one.java 处获得异常块,但是在那之后我如何停止线程,因为即使在该线程似乎继续正常进程之后。
对线程概念不熟悉,请帮忙..
【问题讨论】:
-
这可能会让你感兴趣stackoverflow.com/questions/10961714/… ?
标签: java multithreading interrupted-exception