To track user activity history on a web application, I am attempting to save some session data to a database when the session is invalidated. My initial approach was to store the data on a javabean with a session scope and have it dump its data to the database through the finalize method.
I figured this wouldn't be a perfect solution due to the unpredictable behavior of finalize, but that it should work and eventually save the data. However, it turned out that this tactic does not reliably achieve the desired results - the data is often not logged even when the session is manually invalidated and the current user is switched.
What might be a better way to save data session data to a database without constantly updating it after every client action? Is there a way to call a specific method upon session invalidation?