Search code examples
javamultithreadingeclipse-rcpjobs

Wait for running jobs on exit of eclipse rcp app


i have an eclipse rcp app that does some work in a child thread periodically (every 5 sec). The thread executes a method to update the Status Line of the app to indicate that the work is finished. It looks like this:

protected void updateStatusBar()
{
     Display.getDefault().asyncExec(new Runnable() {
         @Override
         public void run() {
             PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(MainView.ID).
             getViewSite().getActionBars().getStatusLineManager().setMessage("work finished");   
         }
     });
}

It runs fine. The problem I have is when I close my app I get a Null Pointer Exception with this error from time to time:

Job found still running after platform shutdown. Jobs should be canceled by the plugin >that scheduled them during shutdown: >org.eclipse.ui.internal.progress.TaskBarProgressManager$2

The problem is that the job is running because of the async execution but at the same time everything is destroyed because of the closing application. So is there a way to get / wait for the running UI jobs, so that I can make sure the jobs are finished before the app is closed?


Solution

  • Exception message seems to indicate that you schedule the setMessage during shutdown, so probably prefixing your code with something like if (PlatformUI.getWorkbench().isClosing()) return; should help. Otherwise, try changing asyncExec to syncExec to see if problem disappears.