在最近的项目中使用 Dom4j 解析 xml 发现性能低下,有锁竞争的情况,解决如下:

1 SAXParserFactory factory = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
2 factory.setValidating(false);
3 factory.setNamespaceAware(false);
4 SAXReader reader = new SAXReader();
5 reader.setXMLReader(factory.newSAXParser().getXMLReader());
6 Document document = reader.read(new InputSource(new StringReader(xmlString)));
7 Node node = document.selectSingleNode(xpath);

选择使用 xerces 的 XMLReader 进行解析,问题解决。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2021-11-01
  • 2022-12-23
  • 2021-07-04
  • 2021-11-29
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案