• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

get all Session ?

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a method which I can use to get all active session?
My application has a memory leak, because I have an object of UserSessionBeans, that keeps getting added to each time a user logs in. How do I tell if a session has expired, so that I can remove the UserSessionBean from my container?
Thanks
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please don't crosspost. It makes it difficult to follow a conversation.
Why are you compiling user session objects? When a request enters a servlet you can get the current session with HttpServletRequest.getSession() so I wouldn't think you'd need to compile a list of them. There is no notification when a session expires, either. You could have a reaper thread iterate through the list every once in a while and check the HttpSession.getLastAccessedTime to see if it's longer than your session timeout, but first I'd question keeping the session objects around in the first place.
 
Blikkies Marais
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need the UserSessionBean object because it contains info for the application.
You say I should do: HttpSession.getLastAccessedTime(). But how do I get a handle on the HttpSession object? (I have got the sessionId). I want to get a handle on the HttpSession object not from the current request. That is why I ask is it possible to get a list of all HttpSession objects on the server?
 
Blikkies Marais
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I forgot to mention, I have a thread running that cleans up all invalid UserSessionBean objects. So what I would like to do is check if the UserSessionBean object should still persist, ie. if it still has a matching active session.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Blikkies Marais:
I need the UserSessionBean object because it contains info for the application.


Sorry. I thought you were keeping instances of HttpSession in your list.
Why don't you store it in the HttpSession instance (put/getValue())? Then the bean goes away when the session is invalidated by the container.
[ November 21, 2003: Message edited by: Joe Ess ]
 
Blikkies Marais
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, I think that will be the best solution, thanks for your help.
 
Blikkies Marais
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I found a solution: You can let one of you classes implement HttpSessionBindingListener, you will need to define valueBound(HttpSessionBindingEvent pEvent)& valueUnbound(HttpSessionBindingEvent pEvent) methods. When the server sessions time out the server will invoke the valueUnbound(HttpSessionBindingEvent pEvent) method.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic