Sessions tomcat DesktopCleanup [closed]

asked 2018-02-28 01:13:36 +0800

softteam gravatar image softteam
130 1 8

updated 2018-02-28 22:49:02 +0800

Hi all,

I have an application with user login, when the user log out its easy to clean the session but the user not always use the log out, sometimes just close the page or pages. One session has one or more desktops and when the user close or refresh one page DesktopCleanup is triggered, I use an Integer to know how many desktops the user have on the session so when the user close all desktops I could kill Session, the problem is that when only 1 desktop left if the user refresh this I don't know if the user closed o refresh the page, is there any way to know if DesktopCleanup is triggered by Close or Refresh page?


delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by cor3000
close date 2018-03-05 09:31:05

2 Answers

Sort by ยป oldest newest most voted

answered 2018-03-02 15:33:45 +0800

cor3000 gravatar image cor3000
6280 2 7

technically there is no difference between closing a browser(tab), navigating away for reloading the page. Each of these operation is triggered by the same "onBeforeUnloading"-event listener and will send the same "rmDesktop"-command to the server in order to destroy the desktop (including DesktopCleanup). So unfortunately i can't think of a solution from that angle.

At server side you could do something slightly different (maybe not 100% perfect but maybe good enough).

Once the number goes down to 0 (last desktop destroyed) you can - instead of invalidating the session - set a short maxInactive interval (e.g. 10 seconds) so that the session will not invalidate immediately. If the user just refreshed the page the next request will (hopefully) arrive in time, to reuse the previous session. In your DesktopInit listener you can then again count up to 1 and restore the original maxInactiveInterval to extend the session.

If the user really left the page the session will then timeout after 10 seconds and trigger a SessionCleanup Listener where you can perform your logout/cleanup tasks.

Does this make sense/help with your scenario? As said it's not perfect but a reasonably short period should be sufficient to allow page refresh - while timing out reasonably early otherwise.


link publish delete flag offensive edit

answered 2018-03-02 17:46:10 +0800

softteam gravatar image softteam
130 1 8

we tried and seems that works correctly. Thank you so much.

link publish delete flag offensive edit


thanks for the update. Good to hear!

cor3000 ( 2018-03-05 09:30:43 +0800 )edit

Question tools

1 follower



Asked: 2018-02-28 01:13:36 +0800

Seen: 13 times

Last updated: Mar 02 '18

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More