Hi all,
In our application, we are increment the counter when user login and decrementing the same when user logout. This code is deployed in Weblogic 7.0 Clustered environment. While we doing concurrent users testing, even all the users are logged out we notice the counter is carrying more then zero. I need to know how cluster environment manage the �sessionCount� variable. Or if I use the variable as static, can this problem will solve?
Please check the code below and what is the problem in the code?
public class SessionCounter implements HttpSessionBindingListener {
private static SessionCounter me = new SessionCounter();
private int sessionCount = 0;
private SessionCounter() {
this.sessionCount = 0;
}
public void valueBound(HttpSessionBindingEvent e) {
synchronized(this) {
this.sessionCount++;
}
String message = "valudBound: sessionCount = " + sessionCount;
EMotorolaLogger.logDetail(getClass(), "SessionCounter.valueBound", message);
}
public void valueUnbound(HttpSessionBindingEvent e) {
synchronized(this) {
this.sessionCount--;
}
String message = "valudUnbound: sessionCount = " + sessionCount;
EMotorolaLogger.logDetail(getClass(), "SessionCounter.valueUnbound", message);
}
public int getSessionCount() {
return this.sessionCount;
}
public static SessionCounter getInstance() {
return me;
}
}