• Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronized in servlets

 
Bob Moranski
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I came across an example of a ShoppingCart that synchronized its addItem and setNumberOrdered methods. I can understand that they need to be locked up while being mutated so the data won't be corrupted by interference from another thread. And this ShoppingCart is put in a HttpSession object. However, in the servlet that does the ordering, it was the session object that is in a synchronized block. So, I think I am confused is do these mutator methods need to be synchronized when the session object is "held" in the synchronized block?
Thanks.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!