关于controller的一点疑问
一般情况下,spring中的controller是单例模式的,也就是说所有的访问都会调用同一个controller的方法,自然而然的就会想到并发的问题,当某一个请求调用controller方法尚未退出时,是否会造成后续请求的阻塞。
写个小demo测试一下
@RequestMapping("/dotest01/{id}")
@ResponseBody
public String dotest01(@PathVariable("id") int id) {
long start =System.currentTimeMillis();
String str;
if(id==1) {
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.info("1号"+Thread.currentThread().getName());
log.info(this.toString());
str="1号结果!";
}else {
log.info("2号"+Thread.currentThread().getName());
log.info(this.toString());
str="2号结果";
}
long time =System.currentTimeMillis()-start;
return str+time;
}
进行测试先发送访问dotest01/1,后访问dotest01/2