Timer and Tomcat

Good Morning,
I’m typing to discuss about the timer and his function. I have a webapplication with some components. Every component contains a timer updating the UI with different periods. I want stop all the timers when I close the browser, but they continue to run. At the moment I can stop them just closing tomcat…

You could catch a UIDetachException inside the Timer and cancel/interrupt it when it’s thrown. Or cancel the timers manually when a UI - DetachListener is called.
Then you just have to have a good Browser Close detection using Session timeouts and heartbeats (maybe even closeIdleSession=true).

To expand a little on what Marius said: there is no 100% reliable way of detecting exactly when the browser is closed (the browser might just crash or lose its network connection or might not allow reporting back to the server on closing a tab) but using session expiration the way Marius told at least allows you to get a notification about these eventually, with a little delay.

Ok, I solved overriding detach function on the component. Setting “1” on web.xml (session parameter) timer ends after 1 minute and 30 seconds… Thanks