*
The moose likes Servlets and the fly likes How many Session Objects  ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How many Session Objects  ??" Watch "How many Session Objects  ??" New topic
Author

How many Session Objects ??

Saima Khan
Greenhorn

Joined: Jan 15, 2002
Posts: 6
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

Joined: Feb 20, 2001
Posts: 3695

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

Joined: Jan 15, 2002
Posts: 6
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

Joined: Feb 20, 2001
Posts: 3695

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

Joined: Jan 15, 2002
Posts: 6
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

Joined: Oct 25, 2000
Posts: 124
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


Try and Try Till u succeed<br /> <br />Sandeep Jain
Saima Khan
Greenhorn

Joined: Jan 15, 2002
Posts: 6
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

Joined: Aug 17, 2001
Posts: 52
hi!
sandeep how do you remove user name from your hastable..in case of session time out..
thankx
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Satyendra, you will need to implement the HttpSessionBindingListener interface, and put the code to update the hashtable in the value unbound method.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How many Session Objects ??
 
Similar Threads
How many ways can we create an object
jboss reliability
SCA
How to map a tagged item?
Cert nightmare