https://bbs.csdn.net/topics/392049342?page=1
https://blog.csdn.net/wjs19930820/article/details/79848531
https://bbs.csdn.net/topics/392325919?page=1
springmvc默認是單例的,每一個請求進入,都會啟動一個線程,會存在線程安全問題,即最好不要在controller,service層使用全局變量,如果存在對全局變量的修改,會出現線程安全問題。
https://www.cnblogs.com/xjx199403/p/10691659.html
測試驗證的代碼:
@RestController
public class MyTest {
public int count=0;
@RequestMapping("mytest")
public String mytest() throws InterruptedException {
int temp = count;
System.out.println(temp);
int j=0;
while (j<2000000000){
j++;
}
count++;
return "jjj";
}
}
連續請求,觀察輸出的值即可發現問題。或者用測試工具jmeter測試,則去掉里面的while循環。