Can't get ArrayIndexOutOfBoundsException from Future<?> and SwingWorker if thread starts Executor

后端 未结 2 1165
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 02:07

I play with multitreading for SwingWorker by using Executor, and I\'m there by mistake identified wrong elements from the Vector, looks like as this code pretty ignores that

2条回答
  •  抹茶落季
    2020-11-22 02:38

    I think the problem you're running into is that exceptions caught in the background thread are only re-thrown if you call get() when processing is complete. This seems to be a common problem with SwingWorker.

    You can change your done() function to:

    @Override
    protected void done() {
        if (str.equals("StartShedule")) {
           try {
              get();
           }
           catch (Exception ex) {
              // This exception was thrown during processing
              ex.printStackTrace();
           }
        }
    }
    

    done() gets executed on the event dispatch thread so you can display any error messages you need to from there. I hope that helps some.

提交回复
热议问题