When a JSP is requested for the first time or when the web app starts up, the servlet container will compile it into a class extending HttpServlet and use it during the web app's lifetime (source).
JSP have a Page Directive Attributes. You can check it in the specification
Specifically, there is a attribute that you can change on the page:
<%@ page isThreadSafe="false" %>
This attribute indicates the level of thread safety implemented in the page.
- If falsethen the JSP container shall dispatch multiple outstanding
client requests, one at a time, in the order they were received, to
the page implementation for processing.
- If truethen the JSP container may choose to dispatch multiple outstanding client requests to the page simultaneously.
Page authors using true must ensure that they properly
synchronize access to the shared state of the page.
Default is true.
Note that even if the isThreadSafe attribute is false the JSP
page author must ensure that accesses to any shared objects
are properly synchronized. The objects may be shared in
either the ServletContext or the HttpSession.
So, if you set the isThreadSafe attribute to false (thus that the resulting servlet should implement the SingleThreadModel) and you make sure that your scriplet do not use objects that shared in either the ServletContext or the HttpSession, then it may be a good way to resolve the concurrency issues.