title: Why task is done when first element in the future list is true?
body: <p>I'm little confused with tasks in Java multithreading.
  Namely, I've 15 objects, which implements Callable and i'm submitting it by ExecutorService. Each Callable has its own progress bar with is updating in for loop with setProgress method.
  I want to show 3 of 15 callables which will finish their job in first, second and third position by getting their names and setting it to labels on my scene. Of course each callable has different working time.</p>
  
  <p>I created Task and i'm starting it in new thread and iterating over list of future tasks from my ExecutorService.
  The problem is that my labels aren't visible until first element of the future list is true (until first thread is finished). I have really no idea why and i would be very grateful for your help.</p>
  
  <pre><code>public void startButtonClicked() {
      Task task = new Task&lt;Void&gt;() {
          @Override
          public Void call() {
              int i = 0;
              while (i &lt; 3) {
                  for (Future&lt;Boolean&gt; future : futures) {
                      try {
                          if (future.get() == true &amp;&amp; i == 0) {
                              labelFirst.setVisible(true);
                              i++;
                          }
  
                          if (future.get() == true &amp;&amp; i == 1) {
                              labelSecond.setVisible(true);
                              i++;
                          }
  
                          if (future.get() == true &amp;&amp; i == 2) {
                              labelThird.setVisible(true);
                              i++;
                          }
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      } catch (ExecutionException e) {
                          e.printStackTrace();
                      }
                  }
              }
  
              return null;
          }
      };
  
      for (Callable c : callables) {
          futures.add(executorService.submit(c));
      }
      new Thread(task).start();
  
      executorService.shutdown();
  }
  </code></pre>
  
  <p>In my ideal solution each label will become visible when their callable will finish, so labelSecond should appear some time after labelFirst.
  It's my call method in my callable:</p>
  
  <pre><code>public Boolean call() {
      double raceTime = ThreadLocalRandom.current().nextDouble(45.0, 60.0);
  
      try {
          for (double i = 0; i &lt; raceTime; i += 0.01) {
              TimeUnit.MILLISECONDS.sleep(1);
              progressBar.setProgress(i / raceTime);
          }
      } catch (ParseException e) {
          e.printStackTrace();
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
  
      return true;
  }
  </code></pre>
  
  <p>EDIT:
  With checking future.isDone() and little changes it works as i wished.</p>
  
  <pre><code>public void startButtonClicked() {
          Task task = new Task&lt;Void&gt;() {
              @Override
              public Void call() {
                  int i = 0;
                  while (i &lt; 3) {
                      i = 0;
                      for (Future&lt;Boolean&gt; future : futures) {
                          if (future.isDone() == true) i++;
  
                          if (i == 1) {
                              labelFirst.setVisible(true);
                              labelFirstCyclistName.setVisible(true);
                          }
  
                          if (i == 2) {
                              labelSecond.setVisible(true);
                              labelSecondCyclistName.setVisible(true);
                          }
  
                          if (i == 3) {
                              labelThird.setVisible(true);
                              labelThirdCyclistName.setVisible(true);
                          }
                      }
                  }
  
                  return null;
              }
          };
  
          for (Cyclist c : cyclists) {
              futures.add(executorService.submit(c));
          }
          new Thread(task).start();
  
          executorService.shutdown();
      }
  </code></pre>