Why does SwingWorker stop unexpectedly?

前端 未结 4 820
醉酒成梦
醉酒成梦 2020-12-07 01:19

I wanted to try out some ideas using SwingWorker since I haven\'t used it too much. Instead, I ran into an issue and I can\'t figure out what\'s wrong.

4条回答
  •  天命终不由人
    2020-12-07 02:17

    I believe that you need to show a visualized Swing top level Window in order to keep the Swing event thread alive. Otherwise the program will shut down for lack of non-daemon threads.

    Edit:
    To prove that the SwingWorker thread is a Daemon thread, just add a line of code to test it:

    System.out.println("I am thread with " + ms + " sleep in iteration "
       + i + ": " + t.getName() + " (" + t.getId() + ")");
    
    // **** added
    System.out.println("Daemon?: " + Thread.currentThread().isDaemon()); 
    

提交回复
热议问题