Tracking requests without counting

J

Jack

Hello,

In a Servlet (in Tomcat) is there a way to obtain the number of active
sessions or current requests without having to create some kind of
counter which is incremented as sessions arrive (maybe through a
filter) and decremented as sessions leave (maybe through a filter).

For example, is there something in the ServletContext or anything
similar?

I think the Tomcat manager displays the number of current sessions,
does it use an API for this? If so, can I use the same API within a
servlet?

Many thanks,
Jack
 
G

gunduzcan

Hello,

In a Servlet (in Tomcat) is there a way to obtain the number of active
sessions or current requests without having to create some kind of
counter which is incremented as sessions arrive (maybe through a
filter) and decremented as sessions leave (maybe through a filter).

For example, is there something in the ServletContext or anything
similar?

I think the Tomcat manager displays the number of current sessions,
does it use an API for this? If so, can I use the same API within a
servlet?

Many thanks,
Jack

Try using SessionListener for monitoring session activity.

Gunduz
 
J

Jack

Try using SessionListener for monitoring session activity.

Gunduz

Hi Gunduz,

Thank you for your response.

If I implement SessionListener, and am subsequently notified of
session activity, presumably I would then increment or decrement a
counter of some-kind. I am trying to avoid this. Have I missed
something?

Cheers,
Jack
 
A

Arne Vajhøj

Jack said:
If I implement SessionListener, and am subsequently notified of
session activity, presumably I would then increment or decrement a
counter of some-kind. I am trying to avoid this. Have I missed
something?

It is fundamentally impossible to keep track of something
that increases and decreases without keeping track of it.

The only question is whether the server does it for you or you
have to do it yourself.

And if relying on the standard then you have to do it
yourself.

It is very few lines and you should be able to find
plenty of examples.

Arne
 
J

Jack

Hello Arne,

Thank you for you response.

It is fundamentally impossible to keep track of something
that increases and decreases without keeping track of it.

Er, OK. I mean, I could use an API which does the counting for me?
That was I don't have to keep track of it.
The only question is whether the server does it for you or you
have to do it yourself.

Yes, this was my original question.
And if relying on the standard then you have to do it
yourself.

So your saying the standard way is to do it yourself, but you're also
suggesting that I could NOT rely on the standard, and therefore do it
another way? What is this other way?
It is very few lines and you should be able to find
plenty of examples.

It is not the number of lines of code or complexity etc. I have a
rather strange situation where I am trying to find a solution whereby
I do not have to program a counter, but that Tomcat does this for me.
This was my original question.

Cheers,
Jack



Yes, this is my original question. Is there a way to OBTAIN the
number of active sessions. I phrased this carefully, since I didn't
want to keep track of them myself.

I'm confused about your sentence 'if relying on the standard then you
have to do it yourself'.
 
J

Jack

Hello Arne,

Thank you for you response.




Er, OK. I mean, I could use an API which does the counting for me?
That was I don't have to keep track of it.




Yes, this was my original question.




So your saying the standard way is to do it yourself, but you're also
suggesting that I could NOT rely on the standard, and therefore do it
another way? What is this other way?




It is not the number of lines of code or complexity etc. I have a
rather strange situation where I am trying to find a solution whereby
I do not have to program a counter, but that Tomcat does this for me.
This was my original question.




Cheers,
Jack

Yes, this is my original question. Is there a way to OBTAIN the
number of active sessions. I phrased this carefully, since I didn't
want to keep track of them myself.

I'm confused about your sentence 'if relying on the standard then you
have to do it yourself'.

Typo, it should read 'That way I don't have to keep track of it.' not
'That was I don't have to keep track of it.'
 
A

Arne Vajhøj

Jack said:
So your saying the standard way is to do it yourself, but you're also
suggesting that I could NOT rely on the standard, and therefore do it
another way? What is this other way?

I believe that:
- there are no way specified in the Java EE standard to ask the
container for the info
- there may be app server specific ways of doing it

I would not recommend using app server specific ways to avoid
writing so little and so trivial code.

And BTW I don't know any app server specific way for any of
the servers I have been using. But then I have not been
looking for it.
It is not the number of lines of code or complexity etc. I have a
rather strange situation where I am trying to find a solution whereby
I do not have to program a counter, but that Tomcat does this for me.
This was my original question.

You have a very unusual context. Don't expect a standard solution
for it.

Arne
 

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

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top