synchronized in servlets
posted 16 years ago
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?