-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
I'd like to monitor (via JMX) how many users are connected to my application.
I discovered the org.zkoss.zk.ui.util.Statistics class. After some testing (WebLogic 10.3 + ZK 5.0) and many Session timeouts, the activeSessionCount becomes negative. This may be possible since Statistics is not thread-safe.
So I developped my own Monitor implementation replacing ints by AtomicInts:
public class ZkMetrics implements Monitor {
private final AtomicInteger activeSessionCount = new AtomicInteger();
public int getActiveSessionCount() {
return activeSessionCount.get();
}
public void sessionCreated(Session sess) {
activeSessionCount.incrementAndGet();
}
public void sessionDestroyed(Session sess) {
activeSessionCount.decrementAndGet();
}
...
}
Even with that change, sessionCount was still becoming negative after some time. Obviously sessionDestroyed is called more than sessionCreated: so I have to maintain a sessionId set:
public class ZkMetrics implements Monitor {
private final Set<String> activeSessionIds = Collections.synchronizedSet(new HashSet<String>());
public int getActiveSessionCount() {
return activeSessionIds.size();
}
private static String getSessionId(Session session) {
return ((HttpSession) session.getNativeSession()).getId();
}
public void sessionCreated(Session sess) {
activeSessionIds.add(getSessionId(sess));
}
public void sessionDestroyed(Session sess) {
activeSessionIds.remove(getSessionId(sess));
}
I can't tell whether the problem is related to ZK or WebLogic, did some of you experiment similar thing?
How is the ZK listener related to JavaEE HttpSessionListener?
Thanks for advice
After investigating the problem seems related to session fixation in WebLogic 10.3, see http://tracker.zkoss.org/browse/ZK-1734
Asked: 2013-01-24 10:34:16 +0800
Seen: 28 times
Last updated: Apr 23 '13
Using an AtomicInteger should work fine. Are you by any chance using serializable sessions? Have you configured any kind of clustering or are you using SerializableUiFactory in zk.xml?
gekkio ( 2013-01-26 19:36:26 +0800 )editYes clustering is enabled but using sticky sessions. Not using SerializableUiFactory
gquintana ( 2013-04-03 11:53:17 +0800 )edit