Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How many Session Objects ??

 
Saima Khan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I want to know that how many users currently communicating with my web-application .Is there
any way to find out Using Java Servlet Api may be using ServletContext .
I appreciate any help .
Saima.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the Tomcat-Users mailing list:
In a servlet 2.3 environment (Tomcat 4), you can accomplish your goal
without getting into the innards of the container. Simple create and
register an HttpSessionListener, which will be notified every time a
session within your app is created or destroyed -- it's easy to maintain a
local HashMap (or something) of the currently active sessions.
Craig

Does anyone know if there's a way to get some kind of a reference to all of
the active sessions in a webapp? I just want to know how many Sessions
there are.
I'd just like to be able to say something like "There are currently X Number
of users online" on some page.
-Cavan Morris
 
Saima Khan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Carig,
Thanks for your reply ,but actually you repeated my question .As I was also asking about the no of users currently online to communicate simultaneously with any web-aps.
This is interesting thing and there must be some solution .
Thanks anyway .

Saima Khan.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Umm.. I think you need to read that again.

This is Mike, posting a request/response email from two other people, one of whom is named Craig.

(At least one) solution to your problem is *in* that quote. Extrapolate beyond the information given. Think HashMap.size()
[ January 16, 2002: Message edited by: Mike Curwen ]
 
Saima Khan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mike ,
Sorry for the misunderstanding .
But I am still unable to know the total no of users using HttpSessionListener.
Bye
 
Sandeep Jain
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Khan ,
What u need to do is this ..
1) u need to declare a Haspmapor a Hashtable in the class. This u must me doing(i hope) to keep track, that the user doesnt log on two from two machine simaltaneously , any how even if u havent ,no problem .
2) everytime a user logs on to the ur web
application u have to check whether his login name is already there or not . if it is not there u put his name in the map .
3) every time a person logs out, u remove his name from the hashmap
4) now to find out what exactly ur requirement is what u can do is , u can call size() of the hashmap or table .which will return u the count of number of people who are using your application
 
Saima Khan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Sandeep.
I think now i will solve this if I need anything else further i will let you know .
Thanks again.
 
satyendra adhikari
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
sandeep how do you remove user name from your hastable..in case of session time out..
thankx
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satyendra, you will need to implement the HttpSessionBindingListener interface, and put the code to update the hashtable in the value unbound method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic