Struts1 之中类成员变量的线程问题
Struts1 由于是非线程安全的,action中的成员变量 可能是同时使用的。
现在记录下其编程模式,供之后参考:
公司代码中,提供的 Service 类全部提供了一个 getInstance() 方法来得到该服务的一个单实例类。
?
public class ProductManagerService {
?private static ProductManagerService instance = new ProductManagerService();
?public static ProductManagerService getInstance() {
??return instance;
?}
}
?
Action 中使用这个方法来得到单实例。
public class InsuranceAction extends CommonAction {
?
private ProductManagerService productManagerService = ProductManagerService
???.getInstance();
................
?
}
?
?