刚好有一个需求,对某一个请求的响应要按顺序一个一个来,需要在请求方法前面加synchronized
@ResponseBody
@RequestMapping(value="/testQueue",method = RequestMethod.GET)
public synchronized String testQueue(String billCode){
System.out.println(billCode);
System.out.println(queue);
/*
while( queue != 0){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} */
queue++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
queue--;
return billCode;
}