【发布时间】:2016-11-28 12:11:49
【问题描述】:
我编写了一个小型应用程序,其中包括对 JIRA REST API 的 REST 调用来解决下载问题。我有一个进度条指示下载进度。但是,实际上我需要进行两次 REST 调用。第一个需要在第二个开始之前完成。在他们之间,我需要更新 UI。
下面是一些示例代码:
// Loads the dialog from the fxml file and shows it
@FXML
public void showProgressDialog() {
mainApp.showDownloadProgressDialog();
}
// Retrieves some meta information
public void firstDownload() {
Task<Void> task = new Task<Void>() {
@Override
public Void call() {
// do something
}
};
new Thread(task).start();
}
// Do some UI update
// Retrieves the actual issues
public void secondDownload() {
Task<Void> task = new Task<Void>() {
@Override
public Void call() {
for (int i = 0; i < limit; i++) {
// so something
updateProgress((double) i / (double) limit, max);
}
}
};
new Thread(task).start();
}
// Do some UI update
我怎样才能确保上面显示的所有功能都按照这个顺序执行?
感谢您的帮助!
【问题讨论】:
-
启动任务的2个方法是怎么调用的?为什么不能将它们组合成一个
Task? -
谢谢,现在找到了一个只有一个任务的解决方案!
标签: java javafx concurrency synchronization