Hi I have one web application and i want to get the number of users who are currently accessing t

A

anu

Hi

I have one web application (Tomcat/Java/MySQL) and i want to get the
number of users who are currently accessing the application.

Also I want to get the user details of each user, which is stored in a
database.

How can I do this? Pls help.

Regards
Mary
 
T

tzvika.barenholz

I'm assuming you mean you want to show something to the user like:
"currently 27 users online!".
This is tricky. Some user who has sent a request for a page and is now
looking at it is not "online" in a computer sense, but he or she is
online in the human sense. They're on the site.

I would suggest you add some functionality to your login page that adds
to a list of online user objects. the logout page will remove from that
list.
 
J

Joona I Palaste

I'm assuming you mean you want to show something to the user like:
"currently 27 users online!".
This is tricky. Some user who has sent a request for a page and is now
looking at it is not "online" in a computer sense, but he or she is
online in the human sense. They're on the site.
I would suggest you add some functionality to your login page that adds
to a list of online user objects. the logout page will remove from that
list.

To the OP:
But with this approach, if a user closes the browser without first
logging off, then goes to bed, goes on holiday, or accidentally drops
dead, your application will show him/her as online even though he/she
isn't viewing your page.
I'm afraid that because HTTP is connectionless, your problem is in the
general case unsolvable. You'll have to make do with some approximation,
such as counting users who have sent HTTP requests within the last 30
minutes.
 
B

Betty

Joona I Palaste said:
(e-mail address removed) <[email protected]> scribbled the following:


To the OP:
But with this approach, if a user closes the browser without first
logging off, then goes to bed, goes on holiday, or accidentally drops
dead,

So dropping dead on purpose is ok?
 
P

Peter MacMillan

Betty said:
So dropping dead on purpose is ok?

Well, if you're going to drop dead on purpose you can at least have the
common courtesy to logoff first.
 
K

kjc

Joona said:
To the OP:
But with this approach, if a user closes the browser without first
logging off, then goes to bed, goes on holiday, or accidentally drops
dead, your application will show him/her as online even though he/she
isn't viewing your page.
I'm afraid that because HTTP is connectionless, your problem is in the
general case unsolvable. You'll have to make do with some approximation,
such as counting users who have sent HTTP requests within the last 30
minutes.
Not true, if you use a SessionListener.
 
J

Joona I Palaste

kjc said:
Not true, if you use a SessionListener.

And how is using a SessionListener magically going to turn HTTP into a
connectionful protocol? The bottom line remains, the server is only ever
going to know when the user sends HTTP requests. It isn't going to know
what the user does when he/she *isn't* sending HTTP requests. He/she
might be looking at the page returned by the server, reading it over and
over again. OTOH, he/she could have closed the browser, gone to bed,
gone on holiday, or dropped dead. Your server isn't going to be any
wiser until it gets another HTTP request.
If looking at the page counts as "being on the site" but sleeping, or
being dead, doesn't, then the original problem remains unsolvable.
Either you run the risk of logging the user off while he/she's still
reading the pages, or the risk of keeping the user logged on when he/she
doesn't have anything to do with the page any more.
 
K

kjc

Joona said:
And how is using a SessionListener magically going to turn HTTP into a
connectionful protocol? The bottom line remains, the server is only ever
going to know when the user sends HTTP requests. It isn't going to know
what the user does when he/she *isn't* sending HTTP requests. He/she
might be looking at the page returned by the server, reading it over and
over again. OTOH, he/she could have closed the browser, gone to bed,
gone on holiday, or dropped dead. Your server isn't going to be any
wiser until it gets another HTTP request.
If looking at the page counts as "being on the site" but sleeping, or
being dead, doesn't, then the original problem remains unsolvable.
Either you run the risk of logging the user off while he/she's still
reading the pages, or the risk of keeping the user logged on when he/she
doesn't have anything to do with the page any more.
The original poster referred to "Logging in"
If you login, you have a Session created.
In your web.xml you have a timeout value for a session.
If there isn't activity (navigation etc..) associated with a given
session in N amount of time, the session is invalidated, and is there
are SessionListeners registered, they will be notified.
Once notified, descrement a counter.
 
J

Joona I Palaste

kjc said:
The original poster referred to "Logging in"
If you login, you have a Session created.
In your web.xml you have a timeout value for a session.
If there isn't activity (navigation etc..) associated with a given
session in N amount of time, the session is invalidated, and is there
are SessionListeners registered, they will be notified.
Once notified, descrement a counter.

A timeout value is inherently only an approximation. No matter what you
choose the timeout value as, there is no law forcing users to stop
looking at the site *exactly* when the timeout expires. Some of them
might stop sooner, some of them might stop later. Your server isn't
going to know for sure, it can only guess. This is what I've been saying
all along.
 
K

kjc

Joona said:
A timeout value is inherently only an approximation. No matter what you
choose the timeout value as, there is no law forcing users to stop
looking at the site *exactly* when the timeout expires. Some of them
might stop sooner, some of them might stop later. Your server isn't
going to know for sure, it can only guess. This is what I've been saying
all along.
This has turned into a foolish discussion. Your opinions have no
technical merit in the light current accepted practices, at least in the
J2EE world.
 
J

Joona I Palaste

kjc said:
This has turned into a foolish discussion. Your opinions have no
technical merit in the light current accepted practices, at least in the
J2EE world.

I have known from the start of this discussion that I'm being pedantic
here. However I would not go as far as to say "no technical merit". It's
important to understand the theory behind things, even though in
practice we can use approximations like these to help things.
 
O

Owen Jacobson

This has turned into a foolish discussion. Your opinions have no technical
merit in the light current accepted practices, at least in the J2EE world.

No, he's exactly right. The original poster asked to know how many people
are _currently accessing the application_, which is impossible to
determine due to the structure of HTTP. Sessions approximate this
information but believing that they allow you to accurately determine the
number of users is foolish and wrong.

They're an approximation, at best. A fairly good one, but an
approximation nonetheless.

In fact, Joona suggested the very thing you did (approximate it using a
timeout value) well before you did. It seems to me e's fully
aware of the ways of generating data that satisfies the OP's requirements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top