Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How many users are logged in?  RSS feed

 
Chinmaya Chowdary
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Can you please tell me, how to know, how many users(including guests, admin, managers, etc.) are logged into the site? Thankyou.
 
Keerthi Sagar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chinmaya,
The easiest way is to put an Application Context level variable and maintain the value during User login and logoff.

Regards,
Y. Keerthi Sagar.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But note that many people will leave without logging out so you will also need to listen for sessions expiring.

Bill
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou Keerthi and William. I think, I have to use both application context variable and HttpSessionListener. HttpSessionListener is used to listen when the user is logged in, and increments the variable(static variable) of it every time when the session is created(i.e user is logged in) and decrements when the session is destroyed. And I will set the variable to application context, so every component in the application will be able to see. Is this approach is good or I have to do another one? please clarify. Thankyou.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some containers (like tomcat) track the number of active session. So there may not be a need for your to do this explicitly. When a new session is created simply update a global counter. When the session is unbound decrement this counter. Ensure that multi-thread access to this counter is thread safe
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou Deepak.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!