Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Jobs, UIJobs and Threads oh my!
Jobs, UIJobs and Threads oh my! [message #520073] Thu, 11 March 2010 03:09 Go to next message
Craig Foote is currently offline Craig FooteFriend
Messages: 217
Registered: July 2009
Senior Member
Sorry if this is not the correct place to post on the Jobs API. Please
let me know if there's a better group.

I have some code that starts a Job which occasionally needs to obtain
some information on the main thread. I need to get that information and
pass it to a Job method and continue its processing. That processing
needs to continue happening off the main thread, presumably on the same
worker thread the Job was using.

I tried using a custom UIJob, attaching a JobChangeListener overriding
done(JobChangeEvent), getting the information in that UIJob and
retrieving it in the done() then passing it to the Job method. The
problem is that the Job is now running on the main thread. I tried
storing the original worker Thread and calling setThread() with it but it
had no effect.

I'm kinda new to this so I figure I'm just not using the API correctly.
Can someone point me in the right direction please?

How can I run a Job, occasionally get info on the UI thread, and continue
in the Job?

Craig
Re: Jobs, UIJobs and Threads oh my! [message #520074 is a reply to message #520073] Wed, 10 March 2010 23:04 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 11/03/10 8:39 AM, Craig Foote wrote:
> How can I run a Job, occasionally get info on the UI thread, and continue
> in the Job?

Can't you use Display.syncExec to get the UI thread inside the job?

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: Jobs, UIJobs and Threads oh my! [message #520214 is a reply to message #520074] Thu, 11 March 2010 15:14 Go to previous messageGo to next message
Craig Foote is currently offline Craig FooteFriend
Messages: 217
Registered: July 2009
Senior Member
I'm not sure what you mean by "get the UI thread", or why I would want to get it.

Again, I'm in a Job and I can use either of:

1. Display.getDefault().asyncExec()
2. Display.getDefault().syncExec()
3. UIJob

... to do the work required to be done on the UI thread. My issue is continuing the Job on the worker thread once the UI work is done and use the information that was obtained on the UI thread.

It's kind of the reverse. I'm back in my Job but it's now on the UI thread and needs to be back on the worker thread.

I tried storing the getThread() result in the run() of the Job as an instance variable and then in my UIJob's JobChangeListener's done(), where I get the UI info and call my Job method, calling:

myJob.setThread(myStoredThreadInstance)

...but it continues to run on the UI thread, seemingly ignoring the call.

Craig
Re: Jobs, UIJobs and Threads oh my! [message #520254 is a reply to message #520214] Thu, 11 March 2010 16:54 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 266
Registered: July 2009
Senior Member
When you do a syncExec, your original job should just be waiting for the
work on the UI thread to be done. Once syncExec returns, you should be
back on the original worker thread. Assuming you are not a UIJob, this
should not be the UI thread. You can store the data from the UI thread
in fields of the runnable handed to syncExec and then retrieve it from
there once syncExec has returned.

hth,

Steffen

On 11/03/2010 15:14, Craig Foote wrote:
> I'm not sure what you mean by "get the UI thread", or why I would want
> to get it.
>
> Again, I'm in a Job and I can use either of:
>
> 1. Display.getDefault().asyncExec()
> 2. Display.getDefault().syncExec()
> 3. UIJob
>
> .. to do the work required to be done on the UI thread. My issue is
> continuing the Job on the worker thread once the UI work is done and
> use the information that was obtained on the UI thread.
>
> It's kind of the reverse. I'm back in my Job but it's now on the UI
> thread and needs to be back on the worker thread.
> I tried storing the getThread() result in the run() of the Job as an
> instance variable and then in my UIJob's JobChangeListener's done(),
> where I get the UI info and call my Job method, calling:
>
> myJob.setThread(myStoredThreadInstance)
> ..but it continues to run on the UI thread, seemingly ignoring the call.
>
> Craig
Re: Jobs, UIJobs and Threads oh my! [message #520332 is a reply to message #520073] Thu, 11 March 2010 23:13 Go to previous messageGo to next message
Craig Foote is currently offline Craig FooteFriend
Messages: 217
Registered: July 2009
Senior Member
Thanks guys. I kind of already knew that but I thought there might be a more elegant way of jumping between threads if I used UIJobs with my Job. Anyway I appreciate the comments and will proceed as suggested.

Craig
Re: Jobs, UIJobs and Threads oh my! [message #520540 is a reply to message #520073] Fri, 12 March 2010 18:45 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Just FYI while there's nothing wrong with using a syncExec(*) from a Job
to the main thread to request information (it blocks your Job) you can
also get the same behaviour by using a UIJob to get the information,
scheduling it, and calling uiJob.join() from your Job.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Jobs, UIJobs and Threads oh my! [message #520593 is a reply to message #520540] Sat, 13 March 2010 00:18 Go to previous message
Craig Foote is currently offline Craig FooteFriend
Messages: 217
Registered: July 2009
Senior Member
There still seems to be the issue of what thread I end up on though. I guess I'll have to set a Job instance variable from the UIJob because a JobChangeListener leaves me on the UI thread. This was never about getting the info from the UI thread but rather how to continue in my Job on its worker thread. Setting a Job instance variable from the UI thread just seems a bit of a hack but I guess it will work.

Craig

[Updated on: Sat, 13 March 2010 00:24]

Report message to a moderator

Previous Topic:Adding files to Project's directory and getting path of the project
Next Topic:Anticipating a workbench view
Goto Forum:
  


Current Time: Fri Mar 29 00:33:33 GMT 2024

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

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

Back to the top