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.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Timeout in Vaadin
Hi,
First of all, sorry for my english isn't good ^_^
I am working on a Vaadin project over a year (excellent framework by the way). I've come from PHP language and there is one thing that I miss (i'm not sure if there is a similar here) and it's the "window.setTimeout".
In php (javascript) I can call a function when passing a time (in milliseconds). There is a way to do this in Vaadin?
In most posts, people attach the timeout with the "session-timeout", but i'm not interested in it :)
I hope you can help me.
Thank you!
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 :)
Yeah, it works! This is exactly what I was looking for.
Thank you very much :)