I have a stupid question: Are valueBound and valueUnbound method in HttpSessionBindingListener interface thread safe? I wonder what will happen if the methods are invoked concurrently by multiple clients?
It is very interesting question!!. The session is not thread safe , as there could be more than one request from the same user.So as you said there is a possibility that both the threads try to remove the attribute, but only one thread is scheduled to execute by the opearting system at given time.So one thread removes the attribute , and when the next thread gets to execute it tries to remove the same attribute from session , but nothing happens(read removeAttribute() method of HttpSession). What we discussed above applies to removal or unbinding of an attribute, what happens when you add an attribute is that when a thread adds an attribute , if it already exists it is removed and new one is added .So the attribute implementing HttpSessionBinding listener interface would get its valueUnbound() activated and then when new value is added the valueBound method is activated.In two thread scenarion one thread gets the control does the work of replacing the attribute, and next when the other thread is scheduled to execute by OS , would replace the existing attribute.
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
a bit of art, as a gift, the permaculture playing cards