如何取消SwingWorker的执行?
目前我有两个SwingWorker线程在后台工作。如果发生异常,该方法将停止工作,但该线程仍然运行。
如何停止执行并杀死doInBackground()发生异常的线程?
this.cancel(true)不要破坏/关闭线程。我怎样才能做到这一点?
@Overrideprotected 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
阿波罗的战车
ITMISS
冉冉说
随时随地看视频慕课网APP
相关分类