DataFX: ObservableExecutor Preview

Since December we are working on a new DataFX 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:

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!

Eine Antwort auf DataFX: ObservableExecutor Preview

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>