I created a Countdown component. This countdown starts a timer.
My code works (progressbar is updated accordingly, just removed some code fragments to show you a cleaner code):
[/code]My problem: The timer runs in the background despite the fact that the user leaves the page.
I started the timer with a debug message and closed my browser. The timer is still running.
I added a detach listener to the current UI to cancel the timer:
Then I tried to change the heartbeat interval. Since Vaadin cleans the UI if the client sends no heartbeat I thought thats the solution. So I set the heartbeat to 5 seconds:
[/code]I started the timer once again and closed my browser. Waited about 1 minute… But the timer does not get cancelled its still running in the background.
The detach listener is executed ONLY when I reenter the site.
if I remember correctly, the UI cleanup on vaadin is done only when there is other activity (requests) in the server. In practice this means that one or more UIs may remain in memory until the next request comes in. Usually this is not an issue if the UI/Session footprint is not that large
and there is periodic traffic to the application.
In some projects a dedicated cleanup thread has been implemented to periodically clean up expired UIs. Unfortunately I don’t remember how exactly it was done :( Maybe someone else can chime in?