• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

are valueBound and valueUnbound method thread safe?

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic