多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
![](https://box.kancloud.cn/47cda1396f6fc0190c85ea7526c4d5d4_561x146.png) ![](https://box.kancloud.cn/91661c391be890e00e34051a20e3aad1_351x171.png) ThreadServlet.java ~~~ package zyw.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet(name = "ThreadServlet",urlPatterns = "/thread") public class ThreadServlet extends HttpServlet { //int i = 0; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int i = 0; /* synchronized (this){*/ i++;//第一次访问i已经是1,第二次访问=2 try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { e.printStackTrace(); } response.setContentType("text/html;charset=utf-8"); response.getWriter().write(i + ""); /* }*/ } } ~~~