Servlet is not Thread safe. we can make servlet Thread safe from Single Thread Model Interface.
This interface ensure that servlet can handle only one request at a time. Its a marker interface means no method.
Now implementing Single Thread Model Interface :-
import java.io.IOException;
import java.io.PrintWriter;
public class MyServlet extends HttpServlet implements SingleThreadModel {
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.print("Single Thread");
try {
Thread.sleep(10000);
}catch(Exception e){
e.printStackTrace();
}
out.print("model");
out. close();
}
}