Multithreading with Vaadin

I am trying to shift a process in another thread and the process is completed successfully, but unable to open a notification popup from a different thread to a UI. The log in run method with here message is displayed. But notification is not showing up.

`public class CreateSnapshotView extends VerticalLayout {
private void testView(CreateSnapshot snapshot) {

Dialog dialog = new Dialog(new Label("Open Moves for ");
dialog.add(new CreateSnapshotConfirmOpenMovesView(snapshot, new CreateSnapshotConfirmOpenMovesView.Callback() {

    @Override
    public void yes(CreateSnapshot snapshot) {
        
        User user = (User) UI.getCurrent().getSession().getAttribute("user");
        UI ui = UI.getCurrent();

        TestService testService = new TestService(snapshot,user,ui);
        Thread thread = new Thread(testService);
        thread.start();
        dialog.close();
    }

}));
dialog.setWidth("500px");
dialog.setCloseOnOutsideClick(false);
dialog.open();

}

public class TestService implements Runnable {

private User user;
private CreateSnapshot snapshot;
private DalResponse response;
private final UI ui;

public TestService(CreateSnapshot snapshot, User user, UI ui){
this.snapshot = snapshot;
this.user = user;
this.ui = ui;
}

@Override
public void run() {
  DalResponse response = AppView.cycleCountService.deleteCreateSnapshot(user, snapshot);

    if (response.isSuccess()) {
        log.info("UI test:" + ui);
        log.info("here");
        ui.access(() -> Notification.show("Completed"));
    }
}

}`

Make sure to enable push and keep in mind that Notification::show needs an instance of the UI as Thread local available in the thread - see the call to UI::getCurrent within Notification

I didn’t properly understand your solution. Can you modify it a bit according to my code. Please :pleading_face:

Push or UI::getCurrent?

Both if possible, don’t mind i am new with vaadin.

https://vaadin.com/docs/latest/advanced/server-push

Thank you so much helping out @quirky-zebra

It worked :heart_eyes: where can i come hug you :people_hugging:

All good :man_bowing: