目前我有两个SwingWorker线程在后台执行任务。如果发生异常,方法停止工作,但线程仍在运行。
如果发生异常,我该如何停止执行并杀死doInBackground()
的线程?
this.cancel(true)
不能销毁/关闭线程。我该如何实现这一点?
@Override
protected Boolean doInBackground() throws Exception {
try {
while (true) {
//some code here
return true;
}
} catch (Exception e) {
this.cancel(true); //<-- this not cancel the thread
return false;
}
}
我在Netbeans的调试中看到了这些线程。
'AWT-EventQueue-0' em execução
'AWT-Windows' em execução
'SwingWorker-pool-1-thread-1' em execução
'SwingWorker-pool-1-thread-2' em execução
//*em execução = in execution
doInBackground()
еңЁwhile(true)
еҫӘзҺҜеҶ…йғЁиҝ”еӣһиҖҢдёҚйҳ»еЎһеҗ—пјҹ - jfpoilpret