wood burning stoves 2.0*
The moose likes Servlets and the fly likes Is there any person worked on HashMap and Session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is there any person worked on HashMap and Session" Watch "Is there any person worked on HashMap and Session" New topic
Author

Is there any person worked on HashMap and Session

Nilesh Soni
Greenhorn

Joined: May 14, 2001
Posts: 21
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.
session.putValue("user",user);
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).]
Chris Stehno
Ranch Hand

Joined: Feb 26, 2001
Posts: 180
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)


- Chris Stehno, SCPJ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there any person worked on HashMap and Session
 
Similar Threads
Detection of session timeout
How to automatically display SessionExpired.jsp upon session timeout ?
Some basic doubts on session beans...
Balancing good design versus performance & memory
JSP Compiling and session issue