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.