0
我試圖更新使用任務preogress吧。這是我的代碼:不能做ObservableList.clear()內螺紋
ObservableList<somePOJO> listWithProblem = FXCollections.observableArrayList();
Task task = new Task<Void>() {
@Override
public Void call() throws Exception {
final int max = 10;
int i = 0;
while (i < max) {
if (isCancelled()) {
break;
}
if (i == 0) {
i++;
List<SomePOJO> someList = someActionReturningList();
listWithProblem.clear(); // This list has problem!
if (!someList.isEmpty()) {
for (SomePOJO object : someList) {
listWithProblem.add(object);
}
}
Thread.sleep(1000);
updateProgress(i, max);
} else {
i++;
Thread.sleep(1000);
updateProgress(i, max);
}
}
}
return null;
}
};
ProgressBar bar = new ProgressBar(0);
bar.progressProperty().bind(task.progressProperty());
new Thread(task).start();
看來每次它卡在行listWithProblem.clear();
。如果我刪除它,一切都會好的。我無法弄清楚爲什麼會這樣。感謝您的任何提示!