iterating active java sessions

E

erjdriver

is there a way to iterate active servlet http sessions.

or to be notified when a session is about to
be invalided/expired etc.

it'll be run by an administrative servlet every
night to make sure database resources are
released.

thx
 
M

Manish Pandit

Hi,

You can implement callbacks for your application by implementing the
methods in HttpSessionListener. You can put your notification
logic/cleanup logic in them and configure the implementation class in
your webapp's deployment descriptor.

http://tomcat.apache.org/tomcat-5.0-doc/servletapi/javax/servlet/http/HttpSessionListener.html

I have not come across a way to get a hold of active http sessions -
you might want to store a sessionID and related info in a database when
a session is created (using callbacks) and flag or delete the record
when it expires (again using callbacks). This will give you a handy
list of active sessions on your server, but maintaining such a db if
your website has high traffic might be tricky.

-cheers,
Manish
 
E

erjdriver

thanks makes sense.

when you say save the session-id...wouldn't i have to save the
session objects also somewhere. because i don't think there's
a way to retrieve the object with just the session-id.

Manish said:
you might want to store a sessionID and related info in a database [snipped]
 
E

erjdriver

here's a silly question.

i plan have an object that implements the
HttpSessionListener interface...

now who do i have notify of this object.

i.e. who.addSessionListener( my_new_obj )
 
M

Manish Pandit

You configure it in your web.xml in the <listener> tag. There is no
programmatic stuff involved once you've set it up (ofcourse you've to
implement the callbacks).

The container calls the implementation methods based on the event.

<listener>
<listener-class>your.fully.qualified.classname</listener-class>
</listener>

-cheers,
Manish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,076
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top