public TestBean getBean(String xml){
TestBean testBean = null;
try {
XStream xstream = new XStream(new DomDriver());
xstream.alias("ROOT", TestBean.class);
testBean = (TestBean) xstream.fromXML(xmlStr);
} catch (Exception e) {
throw new Exception("",e);
}
return TestBean;
}
将private static XStream xstream = new XStream(new DomDriver());定义放在全局会导致xstream.alias("ROOT", TestBean.class);注入其他的TestBean.class Bean复用上一次的Bean报错。
在方法中初始化XStream xstream = new XStream(new DomDriver());会因为CompositeClassLoader无法回收导致线程阻塞降低程序性能。
现在因为主进程会重复调用多个XML解析方法同时传入不通的XML报文以及解析成不通的Bean,若重复创建XStream对象,必定导致程序性能下降。
有什么办法可以解决?
问题已解决,由于不通的XML导致XSstream复用,需对每一个方法中的创建的xstream进行类内部私有化定义
可以把代码贴出来吗? 你的意思是通过 类私有化解决的吗?