有些类中会引用全局变量,在多用户多线程情况下引用该全局会造成数据混乱,所以要么不用全局,要么就使用ThreadLocal
// Map对象全局变量
private ThreadLocal<Map<String, List<CdaElement>>> compElementsMap = new ThreadLocal<>();
// 字符串全局变量
private ThreadLocal<String> cdaIdGlobal = new ThreadLocal<String>();
public List<DocErrorInfo> check(){
// 方法中再初始化
compElementsMap.set(new HashMap<String, List<CdaElement>>());
// map对象存值
this.compElementsMap.get().put(comp.getCompId(), elementList);
this.cdaIdGlobal.set(cdaId);
//取值
List<CdaElement> eleList = ccompElementsMap.get().get(compId);
String a = cdaIdGlobal.get()
}