aspose file tools*
The moose likes Websphere and the fly likes Active HttpSessions in Context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Active HttpSessions in Context" Watch "Active HttpSessions in Context" New topic
Author

Active HttpSessions in Context

Mathew Sam
Ranch Hand

Joined: Dec 19, 2001
Posts: 124
Is there any API which allows to find the number of active httpsession in a context?



Regards,
Sam
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
you can use HttpSessionListener interface

create a class implementing this interface. you implement 2 of its methods - 1 is called when any session is created, and 1 when any is destroyed.

so at any moment you can get #created minus #destroyed = count of active

i guess, you might need to know the count, so in that class, you can, for example write the count to a file, or to Sysout.

add this class to the web.xml. and have the server know of this addition. and there you go...
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2057
also, the first time the listener's sessionCreated method is called, put the instance of the listener to the servlet context as an attribute, so every body in the context can use it
Mathew Sam
Ranch Hand

Joined: Dec 19, 2001
Posts: 124
Actually the requirement is to invalidate all the active httpsession when the application is shutdown. I want to get the refernces of all active httpsession to explicity invalidate when the application is stopped.
Mathew Sam
Ranch Hand

Joined: Dec 19, 2001
Posts: 124
Basically looking for the functinality of HttpSessionContext.getIds() which is deprecated.
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
I suppose there is no such public API for this. It would break the security.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Active HttpSessions in Context