title: JavaFX - Task/Background processing - How to call multiple methods in a task?
body: <p>I'm trying to teach myself JavaFX and stumbled over a problem I can't seem to fully understand even after reading anything remotely related I could find.</p>
  
  <p>What I'm trying to do : 
  I basically want to run some quick processing in the background of my JavaFX application so to not block the UI for the user. While this is happening a UI element is put up which then should be removed as soon as the background process is finished.</p>
  
  <p>So what I attempted to do was to just move those method calls into a Task which should then run without making the UI freeze.</p>
  
  <pre><code>Task task = new Task&lt;Void&gt;() {
              @Override
              protected Void call() {
  
                  step1();
                  step2();
                  step3();
              }};
  
  new Thread(task).start();
  </code></pre>
  
  <p>I want to call multiple methods of the class we're currently in, but what's happening instead is that only the first method gets invoked. It seems to me that after step1 has reached it's end it doesn't actually "return" to the Task. I've tried looking up how this works and what I could do but honestly didn't get any smarter. Basically all examples of threading and workers only included how to loop and do recurring things but I really just want a "single execution" but in background.</p>
  
  <p>It's probably a really idiotic thing I'm trying to do and shows my little understanding of this but if anyone could point me into the right direction I'd be very thankful.</p>
  
  <p>Thanks a lot!</p>
  
  <p><strong>Solution :</strong> 
  When working with JavaFX the use of "Platform.runLater(task)" is advisable since a normal Thread cannot interact with the UI. A IllegalStateException will be thrown and the thread is halted/canceled(?). The Task itself can remain unchanged but has to be handed to the Platform to execute it to prevent this issue. I changed that one line and everything was perfect afterwards.</p>
  
  <p>I hope this might help someone, someday :-) </p>