Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using Httpsession reference after session-timout?

Posted on 2001-06-13
4
Medium Priority
?
352 Views
Last Modified: 2008-03-06
I have a servlet class, which has a static hashtable. Whenever each request comes, i put the Httpsession reference in the hashtable. Under certain circumstances, I would make use of the Httpsession references to invalidate some session.

My question is, after the session timeout period, will the Httpsession reference be garbage collected? If so, then will the HttpSession reference be null? Or I will access some 'forbidden' area of the memory?
0
Comment
Question by:syyung6
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:superschlonz
ID: 6185522
As long as you have a reference to the session object it will not be grabage collected
and the reference is still valid.
But perhaps it will throw some exception if you want to access it.
If you use WeakReference for storing the reference to the session it will be garbag
collected and you will be able to track this with ReferenceQueue.
0
 

Author Comment

by:syyung6
ID: 6189083
Could you please explain more about WeakReference?
0
 
LVL 3

Accepted Solution

by:
superschlonz earned 600 total points
ID: 6196177
Since JDK1.2 ther is a package java.lang.ref where you find the class Weakreference.

Normally when you have a reference to an object it will not be garbage collected.
So if you want a reference to an object but also want it to be grabge collected if no
one else uses
If you can use a WeakReference.If you have a reference to your session object you
can just create a new WeakReference with the session object as parameter:

WeakReference wref = new WeakReference( session );

The you add this weak reference to your hash table.
With the get method of Reference you can get the object or if it returns null the object
has been garbage collected.

If you just want to find out when a session times out you can also use the setValue and
getValue methods of HttpSession. If the value object implements HttpSessionBindingListener
it will be notified if it is removed from the session.
I'm not sure but I think that the value will be removed when the session times out.
0
 

Author Comment

by:syyung6
ID: 6200759
Thank you for your help!!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question