相关疑难解决方法(0)

SwingWorker:什么时候被称为完成方法?

Javadoc的done()方法SwingWorker:

在doInBackground方法完成后在Event Dispatch Thread上执行.

我已经找到了在取消工人的情况下不是这样的线索.
Done在每种情况下都会被调用(正常终止或取消),但是当cancelled它没有排入 EDT时,就像正常终止时那样.

done在SwingWorker取消a的情况下调用时是否有一些更精确的分析?

澄清:这个问题不是关于如何做到cancel的SwingWorker.这里假设SwingWorker以正确的方式取消.
而且当它们应该完成时,它不是关于线程仍在工作.

java swing swingworker cancellation

19
推荐指数
2
解决办法
2万
查看次数

即使使用包装类,SwingWorker异常也会丢失

我一直在努力解决SwingWorker的可用性问题,吃掉后台任务中抛出的任何异常,例如,在这个SO线程中描述的.该线程给出了一个很好的问题描述,但没有讨论恢复原始异常.

我已被传递的applet需要向上传播异常.但我甚至无法抓住它.我正在使用此博客条目中的SimpleSwingWorker包装类来尝试解决此问题.这是一个相当小的课程,但我会在这里重新发布它仅供参考.

调用代码看起来很像

try {
    // lots of code here to prepare data, finishing with
    SpecialDataHelper helper = new SpecialDataHelper(...stuff...);
    helper.execute();  // this will call get+done on the actual worker
} catch (Throwable e) {
    // used "Throwable" here in desperation to try and get
    // anything at all to match, including unchecked exceptions
    //
    // no luck, this code is never ever used :-(
}
Run Code Online (Sandbox Code Playgroud)

包装纸:

class SpecialDataHelper extends SimpleSwingWorker {
    public SpecialDataHelper (SpecialData sd) …
Run Code Online (Sandbox Code Playgroud)

java swing swingworker

9
推荐指数
1
解决办法
3894
查看次数

标签 统计

java ×2

swing ×2

swingworker ×2

cancellation ×1