To add on to what skaffman has mentioned, it might seem like you don't need to think about multi-threading when writing a webapp because the Servlet framework/API is oriented completely around implementing methods (service()
, doGet()
, doPost()
, etc) which are invoked once per HTTP request.
Therefore, in a simple application, you can implement these methods in your servlet and/or JSP or whatever and not think about what happens when multiple threads interact.
But the second you start having shared state between servlets or service methods, then without possibly realizing it you are dealing with multiple threads interacting, and if you aren't careful, you will eventually have multi-threading or synchronization issues. You will have to deal with this because in Tomcat (and I assume all servlet containers, although I don't know if it's required by the Servlet spec) each request is handled by (possibly) a different thread. Therefore if you receive two simultaneous requests, these will be handled by two separate threads concurrently (at the same time).