Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

are valueBound and valueUnbound method thread safe?

 
william shen
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Arvind Chavar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic