我已阅读文章17.12 Asynchronous Processing
之间有什么区别:
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
AsyncContext acontext = req.startAsync();
...
}
和
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
Runnable runnable = ...
new Thread(runnable).start();
...
}
答案 0 :(得分:1)
不同之处在于'谁'正在控制线程。当您从请求中获取AsyncContext时,使用其start方法并传递Runnable实例,容器管理线程,在该线程中执行您在Runnable实例中传递的逻辑。使用新线程(runnable).start()
触发线程时不是这种情况