0

Maybe it's a simple question, but I don't get it. When should I use concureency in my javafx project? Is it right that I should use for every task, which do some action in the background, the Concurrency API? So every action in my controller class, which has nothing to do with the UI should be executed in a single task? I really don't get it how to use this right....

Chris
  • 599
  • 3
  • 11
  • 24
  • 1
    See if http://stackoverflow.com/questions/30249493/using-threads-to-make-database-requests/30250308#30250308 helps – James_D Jul 29 '15 at 17:35

1 Answers1

1

Whenever you have a task that may take sometime to get executed or there is a possibility of delayed response, you do not want your JavaFX Application thread to wait for it, because, as long as the JavaFX Application thread waits for the response, the UI becomes unresponsive.

A few examples where you may want to use a background thread is :

  • An I/O operation
  • A web service call

From the JavaFX documentation :

Implementing long-running tasks on the JavaFX Application thread inevitably makes an application UI unresponsive.

On the other hand, if you have minor calculations or some task which can be completed in a jiffy (I am not sure if this is the correct word, but I hope you can relate to what I want to say) and will not put the JavaFX Application thread on wait, you can execute them on the same thread.

ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176