Tutorial

Worker Threads for Background Processing

Use Oorian's worker threads for background processing without blocking the UI.

M. WarbleApril 23, 20261 min read
Worker Threads for Background Processing

Long-running operations shouldn't freeze your UI. Oorian's worker threads let you run background tasks while keeping the interface responsive, with automatic UI updates when complete.

Basic Usage

Button processBtn = new Button("Process Data");
processBtn.registerListener(this, MouseClickedEvent.class);

@Override
public void onEvent(MouseClickedEvent event)
{
    statusLabel.setText("Processing...");
    processBtn.setDisabled(true);

    OorianWorkerThread.create(() -> {
        // Long-running operation
        List<Result> results = dataService.processLargeDataset();

        // Update UI when done
        statusLabel.setText("Processed " + results.size() + " records");
        processBtn.setDisabled(false);
        refreshGrid(results);

        sendUpdate();  // Push changes to browser
    });
}

Progress Updates

OorianWorkerThread.create(() -> {
    List<Item> items = getItems();
    int total = items.size();

    for (int i = 0; i < total; i++)
    {
        processItem(items.get(i));

        // Update progress
        int percent = (i + 1) * 100 / total;
        progressBar.setWidth(percent + "%");
        progressLabel.setText(percent + "% complete");
        sendUpdate();
    }

    statusLabel.setText("Complete!");
    sendUpdate();
});

Conclusion

Worker threads are essential for responsive UIs. Use them for any operation that takes more than a moment, and keep users informed of progress.

Share this article

Related Articles

Tutorial

Oorian's Built-In Accessibility Features

January 19, 2026
Tutorial

Getting Started with Oorian: Your First Java Web Application

December 31, 2025
Deep Dive

Logging and Error Handling in Oorian: A Complete Guide

February 24, 2026