How do I have 1 UI thread wait for another UI thread
I have two UI threads. I want to make sure the first one is finishing running, and then run the other one. How could I do that? Thanks a lot!
UIJob uiJob = new UIJob("settext1") {
public IStatus runInUIThread(IProgressMonitor ipm) {
webBrowser.setText(finalContent);
return Status.OK_STATUS;
}
};
uiJob.schedule();
UIJob uiJob2 = new UIJob("se开发者_运维百科ttext2") {
public IStatus runInUIThread(IProgressMonitor ipm) {
webBrowser.execute(executeMoreFunction);
return Status.OK_STATUS;
}
};
uiJob2.schedule();
From eclipse sdk help:
The UIJob is a Job that runs within the UI Thread via an asyncExec.
It is only one UI thread, two UIJob
:s cannot wait for eachother, it will create a deadlock.
Call the join
method after schedule
.
Waits until this job is finished. This method will block the calling thread until the job has finished executing, or until this thread has been interrupted. If the job has not been scheduled, this method returns immediately. A job must not be joined from within the scope of its run method. If this method is called on a job that reschedules itself from within the run method, the join will return at the end of the first execution. In other words, join will return the first time this job exits the RUNNING state, or as soon as this job enters the NONE state. If this method is called while the job manager is suspended, this job will only be joined if it is already running; if this job is waiting or sleeping, this method returns immediately. Note that there is a deadlock risk when using join. If the calling thread owns a lock or object monitor that the joined thread is waiting for, deadlock will occur.
Read more: http://kickjava.com/src/org/eclipse/core/runtime/jobs/Job.java.htm#ixzz0qWh6Ahhe
精彩评论