深入理解HTTP Session
通过监听Session来统计在线人数
public class OnlineCounter {
private static long online = 0;
public static long getOnline(){
return online;
}
public static void raise(){
online++;
}
public static void reduce(){
online--;
}
}
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class OnlineCounterListener implements HttpSessionListener{
public void sessionCreated(HttpSessionEvent hse) {
OnlineCounter.raise();
}
public void sessionDestroyed(HttpSessionEvent hse){
OnlineCounter.reduce();
}
}
网友评论