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@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)