【发布时间】:2015-01-26 10:30:15
【问题描述】:
我想向用户显示一个简单的进度监视器对话框,同时在应用程序的本地数据库中搜索一些数据并显示在 UI 中。
我目前使用 ProgressMonitorDialog,在其中我使用Display.getDefault().asyncExec 在 UI 线程中执行搜索。现在搜索真的很慢。显示进度对话框、在数据库中执行搜索并将结果显示给用户而不损失性能的正确线程使用是什么。
private void doSearchWithProgressDialog() {
ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(null);
try {
progressDialog.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// display progress monitor dialog while searching
monitor.beginTask("Waiting..."), IProgressMonitor.UNKNOWN);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
// perform database query
doSearchAndDisplayResult();
}
});
monitor.done();
}
});
}
catch (InvocationTargetException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
catch (InterruptedException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
【问题讨论】:
-
这是 Eclipse 插件的一部分吗?如果是,
Job将是合适的。 -
它是 Eclipse RCP 应用程序的一部分。
标签: java multithreading user-interface swt progressdialog