java解析xml文件多个线程同时访问时内存溢出,代码如下:
解析的xml文件大小大概2M-10M,该怎么解决呢?
String sourceFile = ConfigReader.get("data.store.path") + article.getSourceFile();
org.dom4j.Document document = null;
FileInputStream fin = null;
try {
fin = new FileInputStream(new File(sourceFile));
document = new SAXReader().read(fin);
} catch (final FileNotFoundException e) {
final String msg = "内容单元xml文件不存在:" + sourceFile;
log.error(msg, e);
throw new RuntimeException(msg, e);
} catch (final DocumentException e) {
final String msg = "解析内容单元xml文件失败:" + sourceFile;
log.error(msg, e);
throw new RuntimeException(msg, e);
} finally {
IOUtils.closeQuietly(fin);
}
final StringBuilder xpath = new StringBuilder("/KFMP/DOCS/DOC[@GUID='")
.append(article.getGuid()).append("']/").append("CONTENT");
final Node node = document.selectSingleNode(xpath.toString());
final String value = node.getText();
article.setContent(value);
final StringBuilder coordXpath = new StringBuilder("/KFMP/DOCS/DOC[@GUID='")
.append(article.getGuid()).append("']/").append("COORDS");
final Node coordsNode = document.selectSingleNode(coordXpath.toString());
final String coordsValue = coordsNode.getText();
article.setCoords(coordsValue);
final StringBuilder briefXpath = new StringBuilder("/KFMP/DOCS/DOC[@GUID='")
.append(article.getGuid()).append("']/").append("BRIEF");
final Node briefNode = document.selectSingleNode(briefXpath.toString());
final String briefValue = briefNode.getText();
article.setBrief(briefValue);
return article;