This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to detect unused/Inactive sessions from code and remove it

 
jasheer kandath
Greenhorn
Posts: 10
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can we detect unused/inactive sessions (probably from a browser crash / Not logging out ) and remove those sessions. ? I am aware of the session time out feature, apart from that , do we have any better options ?

 
jitu mishra
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya you can go to your browser and press CTRL+SHIFT+DELETE


And you are asking about the session timeout ya you can configure through web.xml
 
jasheer kandath
Greenhorn
Posts: 10
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh.. I think my question is confusing let me rephrase it " How do we detect the inactive sessions inside code and remove it to save memory ? "
 
Paul Clapham
Sheriff
Pie
Posts: 20202
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me guess... you want to run some code on the server which finds out which sessions are "inactive".

As you already said, the timeout period is the tool for cleaning up unused sessions. There is no way to find out, from the server, what the user of a session is doing now. They might be talking to a co-worker or checking Facebook or they might have turned off their computer, but you can't tell. That's why the timeout is there.
 
jasheer kandath
Greenhorn
Posts: 10
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the timeout is kept at some 5 minutes , and in an application which gets used by millions of users, there could be large of number of inactive/unused sessions (cases where the user might not come back to the session , like he closed the browser and went for a movie ). How can we prevent these kind of sessions getting piled up?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. How could you tell the difference between someone who's reading information on the screen, from someone who's gone to the bathroom, from someone who's gone to party likes it's 1999?

The session timeout is the right tool for the job. Why are you against using it?
 
Paul Clapham
Sheriff
Pie
Posts: 20202
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, as you already know, if you choose a 5-minute timeout period then the session is going to exist in your server until 5 minutes has passed without any request from the session's client. So what exactly is your question?

 
jasheer kandath
Greenhorn
Posts: 10
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Apologize for the repeated questions on the same topic, Actually i got this question on an interview and I replied with the mighty answer of session time out tool, but the "Guy" keep telling me there are other better ways .. His point was that starting from the 1st minute to the end of 4th minute there could be lots of unused sessions which might take lots of memory and slow down the application , so the question was to run something like a session cleanup code after 2.5 minutes and balance the memory usage. Any way Paul , bear thanks for the replies and accepted the session time out solution.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2.5 minutes is way too short a time to dump a user. I vote that the interviewer was less than savvy.
 
Paul Clapham
Sheriff
Pie
Posts: 20202
26
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, it was an interview question. Not a real-life question at all then.

I suppose if you did have this problem in real life, you could do something like randomly terminating sessions before they actually timed out. The majority of users wouldn't know whether the timeout period was 5 minutes or 4 minutes anyway, and they wouldn't have been keeping track in most cases. And for those who did want to complain, you would provide one of those phone services where they told the user "Your call is important to us" and then put them on hold for 25 minutes.
 
olivier dutranoit
Ranch Hand
Posts: 81
IBM DB2 Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe a long polling mechanism ( like comet ) can be used? You can check if the client is still there, or if any events in the browser itself are triggered...Of course you will have to use a lot of script, depending how much you want to check...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Polling can't be used as it defeats the entire purpose of this (rather silly) exercise. If the original question is centered around keeping the load on the server to a minimum, a highly expensive technique like Comet will make the situation far far worse.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could store less in the session to save memory? Or save nothing in the session (stateless website.) ?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic