Search code examples
javajspjsp-tags

How does JSP process concurrent requests?


I guess my question is, a JSP is compiled into a single servlet instance that serve multiple requests. How do I make it threadsafe?


Solution

  • Servlets are meant to be immutable. Either no state exists outside of method calls (the servlet is stateless), or any such state will never change (so the state that each thread sees is always the same).

    It's extremely simple to write a threadsafe servlet: never use instance variables. Use method-local variables.