我想在我的Eclipse RAP應用程序的後臺執行查詢,但不會阻塞UI。我遵循這個指南:http://eclipse.org/rap/developers-guide/devguide.php?topic=threads.html&version=2.2在Eclipse RAP應用程序中執行後臺操作
但沒有成功:/
執行查詢,但它總是塊調用時的UI。這裏是我使用的代碼:
final ServerPushSession pushSession = new ServerPushSession();
Runnable bgRunnable = new Runnable() {
public void run() {
// schedule the UI update
display.syncExec(new Runnable() {
public void run() {
try {
//CODE
try {
Thread.sleep(5000);
}
catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
catch (PartInitException e) {
e.printStackTrace();
System.exit(0);
}
setText("updated");
}
});
// close push session when finished
pushSession.stop();
}
};
pushSession.start();
Thread bgThread = new Thread(bgRunnable);
bgThread.setDaemon(true);
bgThread.start();
有沒有人有關於發生了什麼的想法?
呃..據我所知,RAP應用程序在單個UI線程中運行所有內容,因爲它在瀏覽器內。不過,看到實際的答案會很高興。 – GGrec
我還沒有測試過你的代碼,但是因爲你在bgThread上等了5秒時強制執行同步操作,所以我傾向於說UI線程也被迫等待。由於同步強制目標線程不會返回其他任何內容,除非最新的同步*被填滿,否則不能保證保存狀態。所以依次嘗試display.asyncExec – dkeck
@dkeck謝謝你的回答!我已經嘗試都沒有成功已經... – rsy