• 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Is there any person worked on HashMap and Session

Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i have created a HashMap and in which i am storing my all Sessions. Inside session i am storing an object Of type User class (I have called User class inside .jsp page as a Bean). so codingwise it's like this after creating User user object.
monitor.put(user,session) ;
(the session is object Of HttpSession, bydefault we get it in .jsp page and monitor is object Of HashMap class which, i included as a Bean having application scope).
Then i set Maximum inactive time to 200 seconds.
session.setMaxInactiveInterval(200) ;

now the problem is that after 200 seconds session is expire but the HashMap is still having it's objects/entry in it (naturally). so how can i remove it from HashMap as soon as session's time period is over.
i have taken somewhat step for the solution. They are as follows.
1) i have implement HttpSessionBindingListener in Class User and override it's both the methods valueBound() and valueUnBound()
2) when session gets removed valueUnBound() is called successfully but how can i remove the session object from HashMap as we can't access HashMap inside User class.
I hope i have clearly write the question and get someone to help me out.


[This message has been edited by Nilesh Soni (edited May 30, 2001).]
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not entirely familiar with the HttpSessionBindingListener but what I would look into doing is making an extension of the HashMap class (rather than using a HashMap) that listens for the binding events and destroys or cleans itself according to your wishes.
Though ... if you only want that data around during the users session, why not just put your HashMap in the session scope?
Hope this helps
Chris Stehno (Sun Certified Programmer for the Java 2 Platform)
    Bookmark Topic Watch Topic
  • New Topic