3 Replies Latest reply: Apr 26, 2012 4:18 AM by 809490 RSS

    SwingWorker does not call done()

    809490
      Hello

      I have a swing application which loads data from a database. To not block the EDT I use a SwingWorker to call the data.
      public class BigRefreshWorker extends SwingWorker<Void, Void>
      {
           private TableView tv;
           private int newColumns;
           
           public BigRefreshWorker(TableView tv, int newColumns)
           {
                this.tv = tv;
                this.newColumns = newColumns;
           }
           
           @Override
           protected Void doInBackground() throws Exception 
           {
                System.out.println("dispatcher running? " + SwingUtilities.isEventDispatchThread());
                      // calling data from db
                      // [...]
                System.out.println("dispatcher running?? " + SwingUtilities.isEventDispatchThread());
                return null;
           }
           
           @Override
           protected void done() 
           {
                System.out.println("dispatcher running??? " + SwingUtilities.isEventDispatchThread());
                //update view
           }
      }
      Most of the time this works, but sometimes the gui freezes and stops with the following output:
      dispatcher running? false
      dispatcher running?? false
      When this is happening the gui does not take any input from the mouse anymore, so i think the application is hanging in the worker thread, even though the last System.out.println() from doInBackground() gets written.
      Is there anything to do to ensure that the EDT gets called again after doInBackground()?

      Kind regards,
      Chang
        • 1. Re: SwingWorker does not call done()
          Maxideon
          When this is happening the gui does not take any input from the mouse anymore, so i think the application is hanging in the worker thread
          If the worker thread hanged, that wouldn't freeze the GUI. And it's not hanging, it's correctly completing the doInBackground() method and scheduling done() to be executed on the EDT. The done() method is not getting executed because the EDT is stuck elsewhere+.
          • 2. Re: SwingWorker does not call done()
            Kleopatra
            What's TableView? If a Swing component or a model somehow related to a Swing component, make sure you do not access it in doInBackground

            Cheers
            Jeanette
            • 3. Re: SwingWorker does not call done()
              809490
              Thanks Kleopatra, thanks Maxideon

              TableView is not a swing component, but a class written by me and i don't access any swing components in doInBackground(), just db operations. I think i will search now in the listeners where the edt is stuck sometimes...

              Regards,
              Chang