What is HttpSessionListener?

This is used when you want to know how many concurrent users are there.
Example:
Public class MyListener implements HttpSessionListener{
Private static int count;
Public static int getCount(){return count;}
Public void sessionCreated(HttpSessionEvent event){
Count ++}
Public void sessionDestroyed(HttpSessionEvent event){
Count--;}}

Configuring in DD:
<web-app>
………….
<listener>
<listener-class>
MyListener
</listener-class>
</listener>

This will not work if the webapp is distributed on multiple JVM, because there is no way to keep the static variables sync. If the class is loaded on more than one JVM each class will have its own value for the static counter variable.

No comments:

Post a Comment