Skip to content

Observability

frosxt edited this page Jan 20, 2026 · 1 revision

Observability

Task Listeners

Listen to task lifecycle events for logging or monitoring.

public class MonitoringListener implements TaskListener {
    @Override
    public void onStart(TaskContext context) {
        System.out.println("Started: " + context.taskId());
    }

    @Override
    public void onSuccess(TaskContext context) {
        System.out.println("Finished: " + context.duration());
    }

    @Override
    public void onFailure(TaskContext context, Throwable error) {
        System.err.println("Failed: " + error.getMessage());
    }
}

Register it in the spec:

SchedulerSpec.builder()
    .addListener(new MonitoringListener())
    .build();

Metrics Snapshots

Get a point-in-time snapshot of scheduler health.

SchedulerSnapshot snapshot = scheduler.getSnapshot();

long running = snapshot.runningCount();
long failed = snapshot.failedCount();
long completed = snapshot.completedCount();

System.out.printf("Health: %d running, %d failed%n", running, failed);

Clone this wiki locally