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. ...

Get Special Edition Using Java™ 2 Enterprise Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.