Forums Register Login

SessionCounter in Cluster Weblogic environment

+Pie Number of slices to send: Send
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;
}
}
+Pie Number of slices to send: Send
Try using HttpSessionListener instead of HttpSessionBindingListener. Because using session binding listener it will increment the count when any thing will be bound to the session.
+Pie Number of slices to send: Send
Hi,

Thanks for the response. but It is working fine in my local and development weblogic which is not a cluster environment.

Can you tell me, is this problem because of the counter is not declear as static(But the class is singelton class).

Thank you,
Balaji.M
+Pie Number of slices to send: Send
Hi Balaji,

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.

You can find more information on coding JSPs and Servlets for a Weblogic clustered environment.

More on HTTP Session State replication here.
For example:
- Session Data Must Be Serializable
- Use setAttribute to Change Session State

I have one question, what is the key you are using when putting this object in session.

Hope this helps.
Sheldon
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1510 times.
Similar Threads
Can we restrict number of sessions through configuration(web.xml).
Session expire problem with HttpSessionListener
ThreadUnsafe
Invalidate Question
synchronized thread???
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:33:07.