Hi all,
I’m building an application that has to do some stuff in background. To accomplish this I’m using java Timers and TimerTask.
Since these tasks can run for a while, I want to stop them if the user close the browser but I have a problem with Heartbeat interval.
I’ve set it to 2 and I’ve read Vaadin waits 3 heatbeats to fail before starting any UI clean up.
Well, my application looks like this
public class WebUI extends UI implements DetachListener
{
@WebServlet(value = "/*", name="WebUIServlet", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = WebUI.class, heartbeatInterval = 2)
public static class WebUIServlet extends VaadinServlet implements SessionDestroyListener
{
@Override
protected void servletInitialized() throws ServletException
{
super.servletInitialized();
getService().addSessionDestroyListener(this);
}
@Override
public void sessionDestroy(SessionDestroyEvent event)
{
// cleanup task(s)
}
}
@Override
protected void init(VaadinRequest request)
{
addDetachListener(this);
// other code...
}
@Override
public void detach(DetachEvent event)
{
// cleanup task(s)
}
}
My questions:
- Where should I put my cleanup task(s) code? Into sessionDestroy() or detach() method ?
- Why if I’ve set heartbeatInterval to 2, instead of wating 6 minutes for UI cleanup, those methods get called after 25/30 minutes?