GeeCON Prague 2014*
The moose likes Servlets and the fly likes How to count the active users Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "How to count the active users" Watch "How to count the active users" New topic
Author

How to count the active users

Sarah Jones
Greenhorn

Joined: Jul 19, 2004
Posts: 12
Hi,
I have to count the number of active users.
The main problem is how to trace the users who just close the browser window. The session will still alive. In my application the session time out is 4 hours. We cannot reduce that.
The main requirement is to show the message "SYSTEM IS BUSY" when the number of users exceed a particular limit.
Santosh Maskar
Ranch Hand

Joined: Jul 02, 2003
Posts: 226
Hi,
You can use the javascript function to track the Browsers close button,
other wise trap the onclose event geneaqted by the browser and invalidate the session for that active user ,

but this not the soluiton ultimatly. u need to do the server side track

other wise implemnt the forcefully login when user close the browser ,

using onclose u can open the same page and ask him for log off , if u dont have the security filets.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
tracking browser close events isn't guaranteed to work as the browser may or may not fire an onclose event to the currently loaded page on closing.

Short: there's NO way to guarantee that a session on the server indeed has a browser associated with it, you always have to assume it has.

4 hour timeouts are excessive, 30 minutes is pretty much standard and busy sites may reduce that to 5-10 minutes only.


42
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
I suppose you could create a "heartbeat" request fired automatically from the client browser every N seconds with either JavaScript or an applet. If the heartbeat does not show up, assume the user is inactive.
Bill
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
To take a possibly wild left turn ... is the real measure of a busy system the number of users? Maybe you can think of another measure - hits or throughput over last n minutes or users who did something in the last n minutes. Any other ideas?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Originally posted by William Brogden:
I suppose you could create a "heartbeat" request fired automatically from the client browser every N seconds with either JavaScript or an applet. If the heartbeat does not show up, assume the user is inactive.
Bill


Hi Bill,

I have used this approach with a self-refreshing page, first in a normal frame 1 pixel wide so it wont show, and then in an inline frame.
I didnt like the idea too much, but it was a must-have requirement, because the application license a placed a max-users limit.
One issue with this was that if the user opens up more than one windows, there are that many more 'heartbeats' going, leading to more network traffic that originally planned for.

Will using an applet instead of the periodically refreshing page in the frame provide any benefits?

thanks

Sonny


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
 
GeeCON Prague 2014
 
subject: How to count the active users