• Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronized in servlets  RSS feed

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?
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!