Tutorial

Worker Threads for Background Processing

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

M. WarbleJuly 2, 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.

Related Articles

Tutorial

Getting Started with Oorian: Your First Java Web Application

December 31, 2025
Security

Security by Default: How Oorian Protects Your Applications

January 11, 2026
Announcement

Why We Built Oorian: The Story Behind the Framework

January 7, 2026