Forum Stats

  • 3,854,494 Users
  • 2,264,371 Discussions
  • 7,905,705 Comments

Discussions

Dukes Book example Cart synchronized

829740
829740 Member Posts: 10
edited Nov 23, 2011 2:18PM in Java Servlet
Going through the Dukes Bookstore examples.

Why are the shopping cart methods synchronized?

If each user only has one session. Then then only access one servlet at a time.
So there is no need to synchronized access to the cart.
That's my thinking, am I wrong, explain it please?
Thanks

Best Answer

  • DrClap
    DrClap Member Posts: 25,479
    Answer ✓
    If the user clicks fast enough, or the request processing is slow enough, it's possible to have two requests from the same user being processed at the same time. Hence the need to consider thread safety.

Answers

  • DrClap
    DrClap Member Posts: 25,479
    Answer ✓
    If the user clicks fast enough, or the request processing is slow enough, it's possible to have two requests from the same user being processed at the same time. Hence the need to consider thread safety.
This discussion has been closed.