Simple question on using "Job" inside Eclipse [message #779613] |
Mon, 16 January 2012 02:00  |
Eclipse User |
|
|
|
Hi all-
I got a simple question on the "Job" concept in the eclipse plugin platform:
how could I know is a Job is executed in a new thread or in
the current thread?
For example:
new ReportingJob().schedule(); //I simply call schedule();
private class ReportingJob extends Job {
protected IStatus run(IProgressMonitor monitor) {
// ... omitted
return Status.OK_STATUS;
}
}
So, is the above ReportingJob() instance running in a new thread or not?
I found the Worker/Job scheduling mechanism inside eclipse is quite
complex, sometimes, a Job is executed in a new thread, while sometimes not.
it would be great if someone can kindly point me to some reference or tutorials.
thanks very much. Any comments are welcome
-Sai
|
|
|
|
|
|
Re: Simple question on using "Job" inside Eclipse [message #780684 is a reply to message #780456] |
Wed, 18 January 2012 22:24  |
Eclipse User |
|
|
|
Hi Deepak-
Thanks for your answer! Really appreciate your help.
A closely-related question, I also see JDT (and other eclipse components) uses
the class "Action" extensively. Usually, programmers override the
"public void run() "
method to do something. However, I found I still got invalid thread access errors
sometimes when accessing GUI object inside "run()", while sometimes not.
So, I am really wondering are all Action#run must be executed in UI-thread or non-UI thread? or it really depends? If so, could anyone kindly points me to some resources about code in Action is executed?
Thanks a lot
-Sai
Deepak Azad wrote on Tue, 17 January 2012 23:12> As far as I understand, the purpose of "Job" is to make the UI
> responsive and active. Thus, all Jobs should be run in a separate and
> background thread instead of the current thread. Is that right?
Of course a Job will run in a separate thread. It can be instructive to
have a look at org.eclipse.core.runtime.jobs.IJobManager and its
implementation org.eclipse.core.internal.jobs.JobManager.
> //if I want to access UI object here,
> //I must wrap it using asyncExec / syncExec to avoid invalid thread access
> //right?
Yes, or you can simply use UIJob if you want to do this.
--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
|
|
|
Powered by
FUDForum. Page generated in 0.03986 seconds