make a listner by implementing HttpSessionListener
and add each created session to a data structure. . like Map or list
for Map use SessionId as Key
and session object
as value. . . .
Override both sessionCreated(HttpSessionEvent event)
and sessionDestroyed(HttpSessionEvent event)
sessionCreated(HttpSessionEvent event)
method is called when any session is created by container. . and we can do what ever we want to do with it at this creation time. . like add in list or map
sessionDestroyed(HttpSessionEvent event)
is called when ever a session is destroyed or invalidated(either by code or timed out by server). . we can do what ever with it before destroy. . . like total logged time. . remove from list or map. . etc