> On 2/20/06, Simon Steiner <[EMAIL PROTECTED]> wrote: >>Can I get a list of all HttpSession's
>Matthias Wessendorf wrote:
Since there isn't such a method, you can't call it :-) But, you may try HttpSessionListener interface. Inside sessionCreated(HttpSessionEvent hse) you can call hse.getSession() to store them manually inside your ServletContext. Not used this on my own, so I don't know anything about some upcoming issue, just a quick idea ;-)
I haven't tried this either, though I have used HttpSessionListener. You'd have to be sure to remove sessions which are destroyed from your list, otherwise by keeping a reference to them you'd be preventing them from ever being garbage-collected and the list would grow forever. You'd also have to deal with the fact that a session could be destroyed while you are in the middle of processing your list of them. Very messy. It seems to be a common mistake to assume that it's a good idea to cache data from the databse in the session, to prevent a database hit for each page request. But in fact, ORM layers and databases do their own cacheing, so repeat requests for the same data are quicker than the first request. It's better to avoid using the session for database data if you can, after all it makes your app less scaleable. I don't know if this is what Simon had in mind, but I did have a colleague not long ago who wanted to find all sessions in order to invalidate some cached database data in them, so Simon's question reminded me of this. We solved that by attaching a date to the session data, and having another date in application context. If the date in app context was newer, the thread processing the next request for each session would invalidate the data in its own session. Maybe that idea would be of some use to you Simon? Jon -- ..................................................................... Dr Jonathan Harley . . Email: [EMAIL PROTECTED] Zac Parkplatz Ltd . Office Telephone: 024 7633 1375 www.parkplatz.net . Mobile: 079 4116 0423