Besides the properties, in order to find out the status of the task and callbacks (completed, failed, etc.), are there any other differences in the use of the JavaFX task over the plain old Java thread with lambda?
I do not ask what is good or bad, I do not ask what you think I should do, I ask for objective factual differences that can occur when using a task instead of a simple lambda to trigger a background thread in a JavaFX application. In addition to the differences that I have already mentioned.
In the Oracel tutorial for concurrency, under "Why use the javafx.concurrent package"? He says:
If you have special requirements or you need additional power over the code, implementing a desktop background by creating a Runnable object and a new thread is the appropriate way.
besides this, all reasons for using it are Taskequally applicable to Runnable, and I don’t see what special requirements or additional capacities are obtained, I also don’t see what you lose, if nothing but state and callbacks, when choosing Runnableover Task. I see that the use is Taskmuch more verbose:
new Thread(this::doSomething).start();
vs
new Thread(new Task<Void>() {
@Override
protected Void call() throws Exception {
doSomething();
return null;
}
}).start();
My concern would be an unexpected side effect of choosing a shorter, more concise version of the code, which, according to Oracle, should only be used in special cases.
doSomething - , , , . , , Platoform.runLater.