Handling Session Termination
There are two ways a session can be terminated: You force the termination by calling the invalidate method on the session, or the servlet engine times the session out. Depending on what kind of data you store in the session, you might need to perform some kind of cleanup of the session data. For example, you might have a database connection stored in the session, or a connection to an RMI or CORBA service on another machine. Although these resources would eventually be eliminated by Java's garbage collector, you shouldn't keep them open any longer than you need to.
A session object has a callback mechanism to notify an object when it has been associated with a session and when it is no longer associated with a session. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access