← Back

CleanupServlet Add-on

Extended VaadinServlet that provides a cleanup thread to clear out session when all UIs have been closed, without needing to wait for the session timeout




It's possible to close a browser window in such way that neither UI cleanup nor session cleanup will happen until the underlying http session timeouts. This can happen because the design idea for heartbeat is to keep the UI alive, not to ensure timely cleanup, and as such the default check is only performed at the end of each request.

This add-on adds a cleanup thread for each session for performing this check at regular intervals to make sure the session cleanup definitely happens. There is also an option for checking each UI for timeouts and closing the session if there are no UIs left, even if the session itself would still have time left.

Use version 1.0.0 for Vaadin 7.4+ projects, and version 2.0.0 for Vaadin 8 projects Note: might work on older Vaadin versions too, haven't tested beyond 7.4.0.

If you'd like to get more features or to modify the existing functionality, there's a link to the source code on the side bar -- it's only two classes, so copying them to your own project shouldn't be much of a hassle. Pull requests are also welcome. You can also leave bug reports and feature requests to the issue tracker, or comment on the discussion forum, although I tend to be very busy so I make no guarantees for delivery.

Sample code

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = CleanupServletDemoUI.class, heartbeatInterval = 1)
    public static class Servlet extends CleanupServlet {
        protected int getCleanupPollingInterval() {
            // how long to wait between session timeout checks
            return 3000;
        protected boolean alwaysCheckUITimeOuts() {
            // if you want to ensure UI cleanup on every check
            // regardless of session timeout, default false
            return true;


(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.


Upgraded to Vaadin 8

Apache License 2.0


Vaadin 8.0+
Vaadin 7.4+ in 1.0.0