Thread problems in Vaadin?

Hi, I was trying to implement a multithreading program with vaadin. The interesting thing (problem) I found is the following. In pseudo-code, if if try:

showPopUpWindowInNewThread(Long Process);
doHeavyCalculationInMainThread();
closePopUpWindow();

Then the popup window is “never” shown (it is shown AFTER the heavy calculation only for a millisecond and then it closes. Thus the processes are not running in order. Of course if we change the threads:

showPopUpWindow(Long Process);
doHeavyCalculationInNewThread();
WaitForNewThreadToFinished → closePopUpWindow();

then everything is ok. Is it a planned behavior of Vaadin? Or is there something important that I missed here?

Thanks
My test code is:

public class LongProcess implements Runnable{
    Window window = new Window();
    boolean finish = false;
    public LongProcess(){
        window.setModal(true);
        window.setClosable(false);
        window.setResizable(false);
        window.setHeight(90.0f, Sizeable.Unit.PERCENTAGE);
        VerticalLayout allert = new VerticalLayout();
        Label msg = new Label("This is a long process");
        ProgressBar wait = new ProgressBar();
        wait.setIndeterminate(true);
        wait.setVisible(true);
        allert.addComponents(msg,wait);
    }

    @Override
    public void run() {
        Notification.show("Started", Notification.Type.ERROR_MESSAGE);
        UI.getCurrent().addWindow(window);
        do{}
        while(finish);
        window.close();  
    }
    
    public void close(){
        finish = true;
    }
    
}
public class TestView extends VerticalLayout{
    LongProcess wait = new LongProcess();
    public TestView(){
        
        Thread thread = new Thread(wait);

        Button buttonStart = new Button("Start");
        buttonStart.addClickListener( e -> {
            thread.start();
            stop();
            
        });
        
        addComponents(buttonStart);
        setMargin(true);
        setSpacing(true);
    }
    
    private void stop(){
        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
            Logger.getLogger(TestView.class.getName()).log(Level.SEVERE, null, ex);
        }
       wait.close();
    }
    
}