| Free tutorials for Java, Eclipse and Web programming |
Version 1.2
Copyright © 2009 - 2011 Lars Vogel
27.03.2011
| Revision History | ||
|---|---|---|
| Revision 0.1 | 12.07.2009 | Lars Vogel |
| Created | ||
| Revision 0.2 - 1.2 | 15.07.2009 - 27.03.2011 | Lars Vogel |
| bug fixes and enhancements | ||
Table of Contents
Eclipse uses one thread which updates the UI. This is true for Eclipse RCP applications and for Eclipse Plugins . This main thread is also called the "UI thread" and is the thread which creates the "org.eclipse.swt.widgets.Display" . All events in this thread will be executed after each other, therefore it is important not to block this thread with long running operations, e.g. network or file access.
The UI thread is also the only one which is allowed to update the UI. If another thread tries to update the UI then you will receive the exception "org.eclipse.swt.SWTException: Invalid thread access". If you need to update the UI from another thread you can use the method syncExec() and asyncExec() on the display object.
// This will update the UI asynchronously, e.g. the calling thread will continue
Display.getDefault().asyncExec(new Runnable() {
public void run() {
... do any work that updates the screen ...
}
}
// This will update the UI synchronously, e.g. the calling thread will wait
// until the work is done
Display.getDefault().syncExec(new Runnable() {
public void run() {
... do any work that updates the screen ...
}
}
The Eclipse Jobs API provides support for running background processes and providing the user also some feedback, e.g. a progress dialog. This API can be used in Eclipse RCP applications or within own Eclipse Plugins .
The important parts of the Job API are:
JobManager - Schedules the jobs
Job - The individual task to perform
IProgressMonitor - UI for Job information
Using the Jobs API in Eclipse RCP is the same as in Eclipse plug-in development. The following assumes basic knowledge of Eclipse RCP or Eclipse Plugins . It also assumes that you are familiar with the Eclipse Commands Framework .