I saw an example with session counter in Sun\'s \"Core Servlets and JavaServer Pages vol 2\".
Counter is simply build on HttpSessionListener
and increments/decr
This would be safe.
public class HttpSessionListenerTest implements HttpSessionListener {
final private AtomicInteger sessionCount = new AtomicInteger(0);
@Override
public void sessionCreated(HttpSessionEvent event) {
sessionCount.incrementAndGet();
}
@Override
public void sessionDestroyed(HttpSessionEvent event) {
sessionCount.decrementAndGet();
}
public int getTotalSessionCount() {
return sessionCount.get();
}
}