DataFX: ObservableExecutor Preview

Since December we are working on a new [DataFX]({{ site.baseurl }}{% link pages/projects/datafx.md %}) version. DataFX will provide a new low level API for multithreading and background tasks in JavaFX. With this API everyone can create new and custom DataSources that will fetch data in background and publish it to JavaFX properties (like you can do with the SwingWorker in Swing). Additionally we will provide some basic concurrency features like the invokeAndWait-method.

Next to this features we created a new Executor class that offers some additional features for the use with JavaFX. The ObservableExecutor holds a ListProperty with all currently scheduled or running tasks. By using this Property you can easily observe all tasks in your UI. We will provide a ListCell class to visualize the running tasks of the executor with only a few lines of code:

Executor executor = new ObservableExecutor();
ListView<Service<?>> list = new ListView<>();
list.setCellFactory(new ServiceListCellFactory());
list.itemsProperty().bind(executor.currentServicesProperty());

The ObservableExecutor uses the wrapper pattern to hold any Executor. Because all task are wrapped into Services you can easily access the title, message or progress of any task. A short example that shows the current state of the API can be found here:

{% include posts/youtube.html id=“eQaVNQKy1U0” %}

Because Runnable & Callable normally do not provide title, message and progress properties we created extended interfaces (DataFXRunnable & DataFXCallable) where all this functions are injected while using them with the ObservableExecutor.

At the current state tasks can be passed to an ObservableExecutor by the following methods:

public <T> Worker<T> submit(Service<T> service);

public <T> Worker<T> submit(Task<T> task);

public <T> Worker<T> submit(Callable<T> callable);

public Worker<Void> submit(Runnable runnable);

public void execute(Runnable runnable);

There are some additional features, too. You can mark a task as not cancelable for example.

Hope you like this stuff!

Hendrik Ebbers

Hendrik Ebbers is the founder of Open Elements. He is a Java champion, a member of JSR expert groups and a JavaOne rockstar. Hendrik is a member of the Eclipse JakartaEE working group (WG) and the Eclipse Adoptium WG. In addition, Hendrik Ebbers is a member of the Board of Directors of the Eclipse Foundation.

Circle Circle
logo

Open Source made right

Privacy

Privacy Policy Cookie Policy Privacy Config Impressum