一部のデータに関連付けられた TableView があり、実行ボタンを押すと、そのデータに対して何らかの処理を実行します。データの各行は個別のスレッドで処理され、それらのスレッドが実行されている間、ProgressInducator がその vbox 内のテーブルを置き換える必要があります。
添付のコードでは:
「WORKS IF STOP HERE」と表示されている場所で停止すると、テーブルが pi に置き換えられます。スレッドが参加するのを待ち続けると、置き換えはありません。私は何が欠けていますか?
runButton.setOnAction(
new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent e) {
List<Thread> threadList = new ArrayList<Thread>();
int threadCounter = 0;
final ProgressIndicator pi = new ProgressIndicator(threadCounter);
vbox.getChildren().clear();
vbox.getChildren().addAll(pi);
for (ProductInTable product : data) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try
{
product.calculate();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
});
threadList.add(thread);
thread.start();
}
int x = threadList.size();
/** WORKS IF STOP HERE **/
// wait for all threads to end
for (Thread t : threadList) {
try {
t.join();
threadCounter++;
pi.setProgress(threadCounter / x);
} catch (InterruptedException interE) {
interE.printStackTrace();
}
}
/** DOESNT WORKS IF STOP HERE **/