The following program :
public class SimpleCounter extends HttpServlet {
int counter=0;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
counter++;
writer.println("accessed " + counter + " times" );
}
}
prints the incremented value of counter every time I access the url of this servlet. I read that the server creates an instance of this servlet and whenever there is a request for this servlet a new thread maps this request to the special instance created by the server.
When does the instance created by the server (to which thread maps the request) die? When do the threads created by a new request die?