|Every instance of ServletExec has a thread that runs in the background which periodically examines all the session objects it is maintaining. When ServletExec determines that a session has been idle (unused) for a period of time that is longer than the configured session timeout value, it calls invalidate() on the session object. ServletExec's implementation of invalidate() removes all attributes that were bound to that session and then removes any references to the session object itself so that the JVM will be able to garbage collect it (and all of its attributes).
If you have objects (attibutes) which you bind to the session and you want to make certain that those objects correctly, and gracefully, release any resources that they might have acquired (run any cleanup code that you want them to), then you have 2 choices:
Have your objects, that you bind to the session object, implement the
This way ServletExec will call
valueUnbound() methods each time the object is added to or removed from the session.
In your implementation of
valueUnbound() you would perform any cleanup or resource releasing that you need to do.
Run your code within the context of a Web Application (WEB-INF folder, web.xml file, etc...) and create a listener that will be notified of Session Attribute Change Events. You would do this by implementing the
In your implementations for
attributeRemoved() you would perform any cleanup or resource releasing that you need to do (depending upon which attribute is being removed).
The exampleWebApp that comes with ServletExec has a simplistic example of a Session Listener which shows how one might do this. Study this to create your own listener and then configure it in your web app.