2016-11-01 1 views
0

나는 이것에 대해 읽고 있고,이 글에서, 나는 버그를에서 그러나SwingWorker의는 doInBackground()를 완료하기 전에() 완료 실행한다

SwingWorker, done() is executed before process() calls are finished

The proper way to handle exceptions thrown by the SwingWorker.doInBackground

될 수 있음을 얻을 내 이 경우 done 메소드를 호출하는 것이 없습니다. 이것은 내 작업자가 작동하는 방식입니다.

public static class collectingWorker extends SwingWorker<Void, Void> { 


    collectingWorker(String name) { 
     //initialize 
     threadName = name; 
    } 

    @Override 
    public Void doInBackground() {  

     loop = true; 
     while(loop){ 
      //Code goes here 
     } 
     return null; 
    } 

    @Override 
    protected void done() { 
     System.out.println("loop: " + loop); 
     System.out.println("Collecting worker DONE"); 
     try { 
      get(); 
     } catch (CancellationException x) { 
      System.out.println("Cancelation"); 
      // ... 
     } catch (InterruptedException x) { 
      System.out.println("Interruption"); 
      // ... 
     } catch (ExecutionException x) { 
      System.out.println("Execution"); 
      System.out.println(x.getMessage()); 
      System.out.println(x.getCause()); 
      // ... 
     } 
    } 
} 

별도의 스레드에서 루프를 false로 설정하기 전에 x 분 기다리는 카운터가 있습니다. 내가 보는 것은 collectWorker done 메서드가 기다려야하는 x 분 전에 실행되고, 상황을 악화 시키거나, 완전히 무작위 적이거나 때로는 작동하고, 때로는 3 분 후에 실패하고 때로는 90 분 후에 실패하는 경우가 있습니다.

그리고 내가 할 방법에 인쇄에서 무엇을 얻을 당신이 볼 수있는이,이다, 부울 "루프는"거짓

loop: true 
Collecting worker DONE 
Execution 
java.util.NoSuchElementException 
java.util.NoSuchElementException 

어떤 아이디어 나 해결책으로 설정되지 않습니다?

답변

0

while (루프) 내에서 중첩 된 논리가 NoSuchElementException을 던져서 전체 doInBackground() 메소드가 조기에 종료됩니다.

관련 문제