Tracking logged in users

To track logged in users in web application , we can use HttpSessionBindingListener.
HttpSessionBindingListener Causes an object to be notified when it is bound to or unbound from a session. The object is notified by an HttpSessionBindingEvent object. This may be as a result of a servlet programmer explicitly unbinding an attribute from a session, due to a session being invalidated, or due to a session timing out.

Code snippet to implement the same :-