Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - volatile variable is not updating
    text
    copied!<p>I'm working on an interactive sorting application in JavaFx:</p> <ul> <li>The numbers are represented by rectangles</li> <li>Every time two numbers are swapped the rectangles are swapped(using timeline - animation)</li> </ul> <p>This is one of the sorting algorithms:</p> <pre><code> public class BubbleSort implements SortAlgorithm { private volatile Boolean swaping; public void sort(double[] array, CompareFunction compareFunction, Model model, Controller controller) { Boolean ord; int i; double aux; swaping = false; do { ord = true; for (i = 0; i &lt; array.length - 1; i++) { if (compareFunction.compare(array[i], array[i + 1]) == false) { while (swaping); swaping = true; aux = array[i]; array[i] = array[i + 1]; array[i + 1] = aux; ord = false; controller.swapRectangles(model.getRectangles().get(i), model.getRectangles().get(i + 1), this); } } } while (ord == false); } public void setSwaping(Boolean swaping) { this.swaping = swaping; } </code></pre> <p>}</p> <p>This is the prototype of the swapRectangles method:</p> <pre><code>public void swapRectangles(final Rectangle rectangle1, final Rectangle rectangle2, final BubbleSort bubbleSort) </code></pre> <p>And when timeline ends I udpate "swaping" value:</p> <pre><code> timeline2.setOnFinished(new EventHandler&lt;ActionEvent&gt;() { @Override public void handle(ActionEvent actionEvent) { setRectangleFill(rectangle2, Color.BLACK); rectangle2.setX(rectangle1X); bubbleSort.setSwaping(false); } }); </code></pre> <p>The problem is that the "swaping" variable is never updating(the setSwaping method is never called).</p> <p>Do you know why? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload