Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Schedule job at startup
Schedule job at startup [message #497081] Thu, 12 November 2009 13:18 Go to next message
Marco Maccaferri is currently offline Marco Maccaferri
Messages: 132
Registered: July 2009
Senior Member
Hello,

I have ported an application running with eclipse 3.2 to the latest
3.5.1 SDK, everthing works well except one thing.

This application needs to start a job at startup, before the main window
opens, and wait until the job finishes before completing the startup.
With eclipse 3.2 I'm starting the job from WorkbenchAdvisor.openWindows
and wait for the completion with Job.join, this works very well.

Now with eclipse 3.5 this doesn't work anymore and I think it is due to
the way the WorkbenchAdvisor methods are called. The job needs to access
the UI thread using syncExec calls, these calls however seems to be
blocked by the startup thread that is already executing a syncExec call
(I'm referring to Workbench.init method at lines 1379-1387), this
results in a deadlock.

I can't use asyncExec calls because the UI accesses needs to be
synchronized with the job and I can't find any workaround to this issue
except starting the job from an IStartup thread, but I would not do that
because it waits for the workbench to be loaded completely and this may
complicate some things a bit.

Is there a solution or a workaround to this problem ?
Other suggestions on how to do that ?

Regards,
Marco.
Re: Schedule job at startup [message #497983 is a reply to message #497081] Fri, 13 November 2009 15:41 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Not any easy ones. The startup model that you have to work with now (probably starting in 3.3) is that the workbench spins the event loop during initialization (it never used to) but prevents a/syncExecs(with some exceptions) from running.

What are you trying to do, exactly? If you write a splash handler, you'll have the opportunity to query the user if that's what you are looking for.

If not, your best bet is to batch all of the changes you'd like to make that have to be on a UI thread, and run them in the postStartup method.

PW


Re: Schedule job at startup [message #498076 is a reply to message #497983] Sat, 14 November 2009 08:48 Go to previous messageGo to next message
Marco Maccaferri is currently offline Marco Maccaferri
Messages: 132
Registered: July 2009
Senior Member
On 13/11/2009 16:41 Paul Webster ha scritto:

> What are you trying to do, exactly? If you write a splash
> handler, you'll have the opportunity to query the user if
> that's what you are looking for.

No, the application I'm working on requires a precalculation of some
data used to display informations to the user, this precalculation
requires a lot of time (up to 2 hours depending on the amount of data to
calculate) and needs to run without views that are accessing the data
itself, but needs the plugins initialized.

The best place I've found to do that is the WorkbenchAdvisor.openWindows
method, windows are not yet open but the plugins are initialized,
unfortunately, since the job needs to display a progress dialog, it hangs.

> If not, your best bet is to batch all of the changes you'd
> like to make that have to be on a UI thread, and run them
> in the postStartup method.

Actually I've found a workaround, first I'm temporarily replacing the
Display synchronizer with the standard Synchronizer so all a/syncExec
can be executed, then I'm running the job code using
ProgressMonitorDialog, at the end the old synchronizer is set back to
display so nothing should be lost. Seems to work well so far.

I think that the synchronizer replace is a sort of hack, hope that the
Display.get/setSynchronizer methods will be kept in future releases.

Regards,
Marco.
Re: Schedule job at startup [message #498342 is a reply to message #498076] Mon, 16 November 2009 14:23 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

That indicates that you need to refactor your plugins into Model and UI so that you can initialize your model headless. "I need the UI to do headless work" indicates a separation is in order.

However, there might be some short term workarounds.

1) your data says when it is ready. Your views can check the flag, and if the data is not ready put up a vanilla "Calculating ..." composite/Label. Your model can fire an "I'm done pre-calculating" event when it's ready.

2) you can start your plugins in the code that needs them. Get their Bundle and then use bundle.start(Bundle.START_TRANSIENT) and don't use asyncExecs anywhere.

Warning: Replacing the synchronizer might work in your own RCP app where you can control what plugins are available, and won't work reliably if your plugin goes into the general Eclipse IDE. And depending on what other plugin contributions do, it can lead to deadlocks.

PW


Previous Topic:simple search for projects(etc..) by name
Next Topic:Activities and Toolbars
Goto Forum:
  


Current Time: Fri Oct 31 18:43:56 GMT 2014

Powered by FUDForum. Page generated in 0.97955 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software