I am working with servlets. When my user logs in, my application is setting his userId and deviceId in a session variable.
Some other part of my application now needs the list of online people and their userId/ deviceId. Note that a user may have simultaneous logins with 2 devices, so we have 2 deviceIds for the same userId.
How should I approach this situation ? I am not willing to use database for tracking the login/ logout functionalities
Store this information also in HttpServletContext’s attribute. This context is global per servlet and can be accsessible by all sessions.
You even can do more. Using HttpSessionAttributeListener you can be notified every time the attribure is added, so if you want to create some kind of monitor application it may be more responsive.