This is a question from HF book chapter 6 coffee cram exam
Which method(s) can be used to ask the container to notify your application whenever a session is about to timeout? (Choose all that apply.)
The Answer given is A and C
But what I think is E should also be notified
the explanation/reason given for Option E which is not correct : removing an attribute isn’t tightly associated with a session timeout
May I know what is the meaning of "isn’t tightly associated with " ??
Well the answer is simple. HttpSessionAttributeListeners are not notified when a session is about to timeout. HttpSessionListeners are made only to be notified about session state. And if you check the API Docs of HttpSessionBindingListener, then this is mentioned specifically there
Causes an object to be notified when it is bound to or unbound from a session. The object is notified by an HttpSessionBindingEvent object. This may be as a result of a servlet programmer explicitly unbinding an attribute from a session, due to a session being invalidated, or due to a session timing out.
This must be mentioned in the servlet specification too but I've not read that so can't tell you the exact section...