I have a List
of tasks that all update a common progress bar called totalProgress
. This bar updates for each task seperately. I have tried creating a DoubleBinding
object to be able to update the progress bar based on the average progress of each task, but it is not working.
Referred post: Multiple Tasks JavaFX
Here is the code I am trying to work with:
double p = 0.0;
for (final Task t : tasks) {
threadPool.submit(t);
DoubleBinding totalProgress = Bindings.createDoubleBinding(new Callable<Double>() {
@Override
public Double call() {
p = (p+t.getProgress()) / tasks.size();
System.out.println("P"+p + "Progress"+t.getProgress());
return p;
}
});
bar.progressProperty().bind(totalProgress);
//bar.progressProperty().bind(t.progressProperty());
t.setOnSucceeded(handler);
}
threadPool.shutdown();