Jump to: navigation, search

Difference between revisions of "FAQ Can I make a job run in the UI thread?"

 
m (Category)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
If you create and schedule a simple job, its <tt>run</tt> method will
+
If you create and schedule a simple job, its <tt>run</tt> method will be called outside the UI thread.  If you want to schedule a job that accesses UI widgets, you should subclass <tt>org.eclipse.ui.progress.UIJob</tt> instead of the base <tt>Job</tt> class.  The UI job&#146;s <tt>runInUIThread</tt> method will, as the name implies, always be invoked from the UI thread.  Make sure that you don&#146;t schedule UI jobs that take a long time to run because anything that runs in the UI thread will make the UI unresponsive until it completes.
be called outside the UI thread.  If you want to schedule a job that accesses
+
UI widgets, you should subclass <tt>org.eclipse.ui.progress.UIJob</tt> instead of the base
+
<tt>Job</tt> class.  The UI job&#146;s <tt>runInUIThread</tt> method will,
+
as the name implies, always be invoked from the UI thread.  Make sure  
+
that you don&#146;t schedule UI jobs that take a long time to run because anything  
+
that runs in the UI thread will make the UI unresponsive until it completes.
+
 
+
 
+
Although running a UI job is much like using the SWT&#146;s <tt>Display</tt> methods
+
<tt>asyncExec</tt> and <tt>timerExec</tt>, UI jobs have a few distinct
+
advantages.
+
 
+
* They can have scheduling rules to prevent them from running concurrently
+
with jobs in other threads that may conflict with them.</li>
+
 
+
* You can install a listener on the job to find out when it completes.</li>
+
 
+
* You can specify a priority on the job so the platform can decide
+
not to run it immediately if it is not as important.</li>
+
  
 +
Although running a UI job is much like using the SWT&#146;s <tt>Display</tt> methods <tt>asyncExec</tt> and <tt>timerExec</tt>, UI jobs have a few distinct  advantages.
  
 +
* They can have scheduling rules to prevent them from running concurrently with jobs in other threads that may conflict with them.
 +
* You can install a listener on the job to find out when it completes.
 +
* You can specify a priority on the job so the platform can decide not to run it immediately if it is not as important.
  
 
== See Also: ==
 
== See Also: ==
 +
*[[FAQ Does the platform have support for concurrency?]]
 +
*[[FAQ Why do I get an invalid thread access exception?]]
  
[[FAQ_Does_the_platform_have_support_for_concurrency%3F]]
+
{{Template:FAQ_Tagline}}
 
+
[[FAQ_Why_do_I_get_an_invalid_thread_access_exception%3F]]
+
  
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
+
[[category:FAQ]]

Latest revision as of 04:02, 30 April 2014

If you create and schedule a simple job, its run method will be called outside the UI thread. If you want to schedule a job that accesses UI widgets, you should subclass org.eclipse.ui.progress.UIJob instead of the base Job class. The UI job’s runInUIThread method will, as the name implies, always be invoked from the UI thread. Make sure that you don’t schedule UI jobs that take a long time to run because anything that runs in the UI thread will make the UI unresponsive until it completes.

Although running a UI job is much like using the SWT’s Display methods asyncExec and timerExec, UI jobs have a few distinct advantages.

  • They can have scheduling rules to prevent them from running concurrently with jobs in other threads that may conflict with them.
  • You can install a listener on the job to find out when it completes.
  • You can specify a priority on the job so the platform can decide not to run it immediately if it is not as important.

See Also:


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.