本文介绍了JDK-7 SwingWorker僵局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型图像处理应用程序,该应用程序使用SwingWorker一次执行多项操作.但是,如果我运行以下代码(摘录过分简化),它只会挂在JDK 7 b70(Windows)上,但可以在6u16中使用.它在另一个工作程序中启动一个新工作程序,并等待其结果(真实应用程序将运行多个子工作程序并等待所有这种方式).我是否在这里使用了一些错误的模式(因为在摆动工作池中通常有3-5个工人,我认为限制为10个)?

I have a small image processing application which does multiple things at once using SwingWorker. However, if I run the following code (oversimplified excerpt), it just hangs on JDK 7 b70 (windows) but works in 6u16. It starts a new worker within another worker and waits for its result (the real app runs multiple sub-workers and waits for all this way). Did I use some wrong patterns here (as mostly there is 3-5 workers in the swingworker-pool, which has limit of 10 I think)?

import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;

public class Swing {
       static SwingWorker<String, Void> getWorker2() {
               return new SwingWorker<String, Void>() {
                       @Override
                       protected String doInBackground() throws Exception {
                               return "Hello World";
                       }
               };
       }
       static void runWorker() {
               SwingWorker<String, Void> worker 
                   = new SwingWorker<String, Void>() {
                       @Override
                       protected String doInBackground() throws Exception {
                               SwingWorker<String, Void> sw2 = getWorker2();
                               sw2.execute();
                               return sw2.get();
                       }
               };
               worker.execute();
               try {
                       System.out.println(worker.get());
               } catch (Exception e) {
                       e.printStackTrace();
               }
       }
       public static void main(String[] args) {
               SwingUtilities.invokeLater(new Runnable() {
                       @Override
                       public void run() {
                               runWorker();
                       }
               });
       }

}

推荐答案

由于还没有人解雇链接,看来这实际上是一个已知的错误:

As nobody has fired off the link yet, it seems this is actually a known bug:

http://bugs.sun.com/bugdatabase/view_bug.do? bug_id = 6880336

令人惊讶的是,对于大多数非平凡的应用程序来说,什么应该成为showtopper错误的投票只有不到100票.

Surprisingly there are less than 100 votes for what should be a showstopper bug for most non-trivial applications.

这篇关于JDK-7 SwingWorker僵局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 02:32