5

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?

assylias
  • 321,522
  • 82
  • 660
  • 783
Biene Maja
  • 313
  • 1
  • 3
  • 9
  • This has nothing to do with your code... it's an error of the platform own code that did not shutdown the jobs. This happens when the workbench closes with a forced PlatformUI.getWorkbench().close() – marcolopes Aug 13 '23 at 05:24

2 Answers2

2

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.

hgrey
  • 3,033
  • 17
  • 21
0

Just do what the message says:

"Jobs should be canceled by the plugin that scheduled them during shutdown"

In the plugin that starts this job, in Activator.stop(), ensure that your Job actually quits and don't continue shutdown before it is completed: wait for the job to end in the stop() method. This of course requires that you design the timer job such, that it reacts immediately to this cancel request and terminates.

You can get much worse messages then the ones above, but since it is a shutdown, many people tend to ignore those. For example assume your plugin A uses a class from plugin B which is not yet loaded. The system shuts down: first it will stop() A, then it will stop() B. If you task is scheduled now, you will get a ClassNotFound for the class in B.

This all is irrelevant (just an error message) if your Eclipse doesn't need to store anything important, but if the proper execution of your Job is important for data consistency of your application, that might lead into more trouble the tool is startet the next time.

Artem Mostyaev
  • 3,874
  • 10
  • 53
  • 60