This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Murach's MySQL and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

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