0

i want to calculate user online or active sessions by HttpSessionEventPublisher my web.xml file as bellow :

 <listener>
        <listener-class>my.web.application.SessionManager</listener-class>
    </listener>

and my class SessionManager is:

import org.springframework.security.web.session.HttpSessionEventPublisher;

import javax.servlet.http.HttpSessionEvent;
public class SessionManager extends HttpSessionEventPublisher {

    private static int userCount;
    @Override
    public void sessionCreated(HttpSessionEvent event) {
        userCount++;
        super.sessionCreated(event);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
        userCount--;
        super.sessionDestroyed(event);
    }

    public static int getUserCount() {
        return userCount;
    }
}

when start application 4 session creating , but should be 1 create session, how to solve my problem? thanks

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Alireza Alallah
  • 2,486
  • 29
  • 35
  • And why should it be 1 session and not 4? You can do concurrent requests and if you use JSP you will always get a session (even if it is a temporary one). You can counter act this by adding `session="false"` to your JSP see http://stackoverflow.com/questions/5093032/how-do-you-disable-session-creation-for-all-jsps-with-tiles – M. Deinum Oct 19 '15 at 12:46
  • i want to calculate online user count , how do it ? with problem, Thanks – Alireza Alallah Oct 19 '15 at 13:00
  • You are using Spring Security then use Spring Security. Judging by the fact that you are extending the `HttpSessionEventPublisher` I also assume you have something for concurrent sessions or session management in place and hence a `SessionRegistry` use that. – M. Deinum Oct 19 '15 at 13:06

0 Answers0