Async Task API in JavaFX1.2
Async Task APIs are located in javafx.async package. These APIs provides a way of starting, stopping and tracking code that does not run on the JavaFX event dispatch thread.
Now let us see how we can use this API.
Step1: implement RunnableFuture Interface and create you Task.
For example -
public class MyTask implements RunnableFuture {
public void run() throws Exception {
//Place your code which you want to execute.
println("Executing the task...");
}
}
Note: Only Java Tasks can be specified here.
Step2: Create JavaTaskBase in your FX code and in create() method return a instance of MyTask.
var task = JavaTaskBase {
public override function create(): RunnableFuture{
return new MyTask() as RunnableFuture;
}
onDone: function():Void { println("I am done..");}
onStart : function():Void { println("About to start");
}
task.start();