You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christian Hauser <c....@active.ch> on 2003/08/12 10:21:23 UTC
HttpSessionListener: Negative session count
Hello J2EE programmers
I wrote a JSP some time ago that uses a class SessionCounter (which
implements HttpSessionListener) to count the active sessions of a web
application and to display them.
Unfortunately there seems to be a problem with my program, because the
web application says that there are currently -18 active sessions.
However, the lowest possible count should be 0.
Of course I could implement the sessionDestroyed the following way (to
prohibit a negative session count, but then the current session count
would not be correct, not?
public void sessionDestroyed(HttpSessionEvent event) {
if (activeSessions > 0)
activeSessions--;
}
Code of JSP file:
<tr>
<td>Concurrent sessions:</td>
<td><%= SessionCounter.getActiveSessions() %></td>
</tr>
<tr>
<td>Last refresh:</td>
<td><%= new Date() %></td>
</tr>
<tr>
<td>Last session change:</td>
<td><%= SessionCounter.getLastChange() %></td>
</tr>
Here's the class SessionCounter, which belongs to a utility JAR that is
situated in the lib directory of The web application.
public class SessionCounter implements HttpSessionListener {
/** Static variable to keep track of the current number of active
sessions. */
private static int activeSessions = 0;
public void sessionCreated(HttpSessionEvent event) {
activeSessions++;
}
public void sessionDestroyed(HttpSessionEvent event) {
activeSessions--;
}
public static int getActiveSessions() {
return activeSessions;
}
}
I'm using Tomcat 4.1.24 and hope that someone of you might give me a
hint on how I can get a reliable session counter.
Christian
Re: HttpSessionListener: Negative session count
Posted by Christian Hauser <c....@active.ch>.
I have a further question:
Is it correct that I don't have to use
<jsp:useBean id="sessionCounter" class="SessionCounter" scope="session" />
and set the scope to "session"?
Because now I don't use "useBean". Should I?
Thank you in advance,
Christian
Christian Hauser wrote:
> Hello J2EE programmers
>
> I wrote a JSP some time ago that uses a class SessionCounter (which
> implements HttpSessionListener) to count the active sessions of a web
> application and to display them.
>
> Unfortunately there seems to be a problem with my program, because the
> web application says that there are currently -18 active sessions.
> However, the lowest possible count should be 0.
>
> Of course I could implement the sessionDestroyed the following way (to
> prohibit a negative session count, but then the current session count
> would not be correct, not?
> public void sessionDestroyed(HttpSessionEvent event) {
> if (activeSessions > 0)
> activeSessions--;
> }
>
> Code of JSP file:
> <tr>
> <td>Concurrent sessions:</td>
> <td><%= SessionCounter.getActiveSessions() %></td>
> </tr>
> <tr>
> <td>Last refresh:</td>
> <td><%= new Date() %></td>
> </tr>
> <tr>
> <td>Last session change:</td>
> <td><%= SessionCounter.getLastChange() %></td>
> </tr>
>
> Here's the class SessionCounter, which belongs to a utility JAR that is
> situated in the lib directory of The web application.
>
> public class SessionCounter implements HttpSessionListener {
>
> /** Static variable to keep track of the current number of active
> sessions. */
> private static int activeSessions = 0;
>
> public void sessionCreated(HttpSessionEvent event) {
> activeSessions++;
> }
>
> public void sessionDestroyed(HttpSessionEvent event) {
> activeSessions--;
> }
>
> public static int getActiveSessions() {
> return activeSessions;
> }
> }
>
>
> I'm using Tomcat 4.1.24 and hope that someone of you might give me a
> hint on how I can get a reliable session counter.
>
> Christian
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
Re: HttpSessionListener: Negative session count
Posted by Christian Hauser <c....@active.ch>.
I have a further question:
Is it correct that I don't have to use
<jsp:useBean id="sessionCounter" class="SessionCounter" scope="session" />
and set the scope to "session"?
Because now I don't use "useBean". Should I?
Thank you in advance,
Christian
Christian Hauser wrote:
> Hello J2EE programmers
>
> I wrote a JSP some time ago that uses a class SessionCounter (which
> implements HttpSessionListener) to count the active sessions of a web
> application and to display them.
>
> Unfortunately there seems to be a problem with my program, because the
> web application says that there are currently -18 active sessions.
> However, the lowest possible count should be 0.
>
> Of course I could implement the sessionDestroyed the following way (to
> prohibit a negative session count, but then the current session count
> would not be correct, not?
> public void sessionDestroyed(HttpSessionEvent event) {
> if (activeSessions > 0)
> activeSessions--;
> }
>
> Code of JSP file:
> <tr>
> <td>Concurrent sessions:</td>
> <td><%= SessionCounter.getActiveSessions() %></td>
> </tr>
> <tr>
> <td>Last refresh:</td>
> <td><%= new Date() %></td>
> </tr>
> <tr>
> <td>Last session change:</td>
> <td><%= SessionCounter.getLastChange() %></td>
> </tr>
>
> Here's the class SessionCounter, which belongs to a utility JAR that is
> situated in the lib directory of The web application.
>
> public class SessionCounter implements HttpSessionListener {
>
> /** Static variable to keep track of the current number of active
> sessions. */
> private static int activeSessions = 0;
>
> public void sessionCreated(HttpSessionEvent event) {
> activeSessions++;
> }
>
> public void sessionDestroyed(HttpSessionEvent event) {
> activeSessions--;
> }
>
> public static int getActiveSessions() {
> return activeSessions;
> }
> }
>
>
> I'm using Tomcat 4.1.24 and hope that someone of you might give me a
> hint on how I can get a reliable session counter.
>
> Christian
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org