esports52
黒鳥
2018-12-27 10:13

Runnable中HttpServletRequest丢失的问题。

  • java
  • tomcat
  • eclipse
public class Test extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();
        T t = new T(req);
        ses.scheduleAtFixedRate(t, 0, 5000, TimeUnit.MILLISECONDS);
    }
}
public class T implements Runnable {
    public HttpServletRequest req;

    public T(HttpServletRequest req){
        this.req = req;
        System.out.println(req.getSession()+"---------------");
    }

    public void run() { 
            System.out.println(req.getSession()+"---------------");
            try {
                Connection conn = JdbcUtil.open();
                conn.setAutoCommit(false);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            System.out.println(req.getSession()+"==============");
    }
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答