Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Timeout in Vaadin

Félix Sandoval Hernández
6 years ago Nov 25, 2015 9:50am
Alejandro Duarte
6 years ago Nov 25, 2015 12:26pm

Hi,

You can use ScheduledExecutorService. If you want the scheduled task to update the UI, you need two more things: Enable Push support, and use UI.access():

@Push
public class ExampleUI extends UI {

    ...

    @Override
    protected void init(VaadinRequest request) {

        ...
      
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        executorService.schedule(this::showNotification, 5000, TimeUnit.MILLISECONDS);
    }

    private void showNotification() {
        UI.getCurrent().access(() -> {
            Notification.show("It works!");
        });
    }

}

Hope that helps :)

Félix Sandoval Hernández
6 years ago Dec 02, 2015 4:04pm