• servlet的多线程并发问题


    package gz.itcast.e_thread;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    /**
     * servlet的多线程并发问题
     * @author APPle
     *
     */
    public class TheradDemo extends HttpServlet {
        
        int count = 1;
    
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=utf-8");
            
            synchronized (TheradDemo.class) {//锁对象必须唯一。建议使用类对象
                response.getWriter().write("你现在是当前网站的第"+count+"个访客");   //线程1执行完  , 线程2执行
            
            //线程1还没有执行count++
            /*try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }*/
                count++;
            }
        }
    
    }
  • 相关阅读:
    chrome视频播放加速
    centos磁盘空间重新分配
    mseed2sac的安装和使用
    查找台站信息得到台站数据的网站
    java install
    CMT learning
    hosts持续更新
    what is SVD and how to calculate it
    google 镜像
    z变换
  • 原文地址:https://www.cnblogs.com/tzzt01/p/7326653.html
Copyright © 2020-2023  润新知