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?
From my understanding of a cluster, it means that there are multiple servers (multiple JVMs) hosting the same application. You could possibly think along these lines.
- Each server would have a separate singleton instance of SessionCounter. Since SessionCounter implements HttpSessionBindingListener, I am assuming that when a user logs in, the application puts this singleton object in session and when the user logs out, the application removes it. But there are multiple instances of SessionCounter in a clustered environment. This is where I think the flaw is.
- Weblogic does provided replication of HttpSession state across all servers in the cluster. SessionCounter would have to be made Serializable for this to happen.