我试图中断一个正常运行的线程(它不处于 sleep() 或 wait() 状态)。
在上网时,我知道中断正常运行的线程只会将标志设置为真并继续该过程。
代码片段是
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 处获得异常块,但是在那之后我如何停止线程,因为即使在该线程似乎继续正常进程之后。
我是线程概念的新手,请帮助..