I want to visualize my Heap sort algorithm using JavaFX, after each swap of the elements in my array, I also swap the values of the two corresponding bars
in a barChart
. The algorithm works fine, but when updating the GUI the runnable
doesn't seem to block the next runnable for it's execution.
That's why my graph is messed up (values aren't swapped in order). See image below:
Here is my runnable code snippet:
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Await");
try {
latch.await();
} catch (InterruptedException ex) {
}
// queuing the done notification into the javafx thread
Platform.runLater(new Runnable() {
@Override
public void run() {
controller.updateChart(parentIndex, childIndex);
}
});
}
}).start();
The latch is declared as class variable, and not modified somewhere else:
final CountDownLatch latch = new CountDownLatch(1);
here the code snippet the runnable is doing:
@Override
public void updateChart(int index1, int index2) {
Object tempObject = series.getData().get(index2);
series.getData().set(index2, series.getData().get(index1));
series.getData().set(index1, tempObject);
barChartCopy.getData().setAll(series);
}
Any idea, why the latch isn't considered?