我的问题是关于 Spring 控制器上的线程安全(最后是 Servlet 类)。
1) 如果我定义一个变量 static final int i =0,它会导致线程安全问题,但是,我已经声明了 static 和 final 2) 将 enum 声明为全局变量,如受保护的 enum Mytype {start,stop} 怎么样?3) 贴花@Autowired 是线程安全的吗?
我已经找到了一篇很好的文章,但我需要更清楚地了解上述问题。 参考
代码:
@Controller
Public class Test{
@Autowired MyTest mt; // Autowired, thread safe?
private final String s = "abc"; // final, threadsafe?
private static final int i =0; // again final threadsafe?
private static int x = 0; // only static threadsafe?
protected enum Mytype{head, tail}; // enum, threadsafe?
.....
}