I was thinking about how websites displays information like :
There are now 400 online guest and 40 registered user.
I am thinking about this implementation :
I developed a session listener that has a counter (this counter increases when any user entered the application).
also, I developed singleton class that has tow counters :
the first, is the previous counter in the previous listener.
the second, is a counter presented the number of registered users.
when a user has done a succesfull login, the singleton decreases the first counter and increases the second counter.
what do you about this approach ? does it has wrong points ?
can I use it in real and working application ?
I didn't see any piece about decrementing the counters. I assume you would subtract from the counter when a session is invalidated or timed out.
Your approach is fine. Just keep in mind that the number of users is a bit overstated. This is due to the fact that a session can be active for a while after the user has left.
in the singleton class, the first counter will decrements 1 when a succesfull login has made and increases the second (not decreases as I wrote)
I assume you would subtract from the counter when a session is invalidated or timed out.
how can I know that ??
thanks for quick response.
And I think for registered user you dont need a counter. yeah ofcourse if it is about registered online users then its fine.
one more thing you mentioned above that you developed a Listener. why not use HttpSessionListener provided by the vendor. Is there any problem with that???
[ September 28, 2004: Message edited by: adeel ansari ]
Originally posted by John Todd:
OOppps, I forgot something.
imagine this scenario :
when a user (guest or registered) close his browser, how could I know that in order to decrement a specific counter ??
Session time out feature will be useful. When the session timeouts sessionDestroyed will be invoked. There will time gap between the user closing the browser and session timing out.
But again when clients power shuts down it would be done using sessionTimeout.