# Javafx Concurrency Services

> Use javafx.concurrent Task and Service correctly for background work and responsive UIs.

- Skill: `johannesrabauer/javafx-concurrency-services` (Agent Skill)
- Install (CLI): `npx skillmds@latest add johannesrabauer/javafx-concurrency-services`
- Raw SKILL.md: https://api.skillmd.com/api/skills/johannesrabauer/javafx-concurrency-services/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Productivity
- Author: JohannesRabauer (https://skillmd.com/u/johannesrabauer)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/johannesrabauer/javafx-concurrency-services

---


# JavaFX Concurrency and Services

Use this skill when expensive work must stay off the JavaFX Application Thread while the UI
remains observable and responsive.

## Example

```java
import javafx.concurrent.Task;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;

public class LoaderView extends VBox {

    public LoaderView() {
        var status = new Label("Idle");
        var progress = new ProgressBar(0);
        var button = new Button("Load");

        button.setOnAction(event -> {
            Task<String> task = new Task<>() {
                @Override
                protected String call() throws Exception {
                    updateMessage("Loading data...");
                    updateProgress(0.5, 1.0);
                    Thread.sleep(250);
                    updateProgress(1.0, 1.0);
                    return "Done";
                }
            };

            status.textProperty().bind(task.messageProperty());
            progress.progressProperty().bind(task.progressProperty());
            task.setOnSucceeded(done -> {
                status.textProperty().unbind();
                status.setText(task.getValue());
            });

            var thread = new Thread(task, "loader-task");
            thread.setDaemon(true);
            thread.start();
        });

        getChildren().addAll(status, progress, button);
    }
}
```

## Setup notes

- Prefer `Task` for one-shot work and `Service` for restartable workflows.
- Bind message and progress properties so the UI reflects worker state without manual polling.
- Keep executor ownership explicit when the application manages many background operations.
- Use `javafx-architecture-frameworks` for overall application service design and
  `javafx-reactive-binding-state` for stream-based state pipelines.

## Gotchas

- Do not touch scene graph nodes from `call()`.
- Unbind UI properties when a completed worker should no longer own the label or progress bar.
- Surface failure states through `setOnFailed(...)` or worker state bindings instead of swallowing
  exceptions.

