I wish to run a function for every user with a session at regular intervals that will check if a user is active. If not active, the function will remove the user from the list of users in the servlet context and clear the user session.
What can I use that will run the function at regular timed intervals for each user?
From what I understand, servletcontextlistener runs only once for the life of the servlet and not for each user so it’s not usable. Also, that using threads is advised against in a servlet.
Edit:
Users (using ajax) call a action which contains function that updates a variable I’ve stored for each user that indicates the last time they contacted the server.
You are probably looking for
javax.servlet.http.HttpSessionListener.Create one, register it in
web.xmland have thesessionDestroyeddo your work.