jdom performance

ぃ、小莉子 提交于 2020-01-04 10:43:05

问题


I am currently using native Java XML processing library (Xerces). I can't use any sax parser because I need random access to xml nodes. I am finding that CPU usage goes 100% when I am parsing XML files. There are large number of small size (1-10kb) that I am processing like this-

while(hasFile){
processXMlfile(hasFile.next);
}

In processXMlfile() I am building parsing and processing file.

If I move to JDOM library, will I gain any performance benefit?


回答1:


The bottleneck is probably XML parsing, and JDOM will likely use the same XML parser under the covers, so it won't make any difference.

A key factor when you are parsing lots of small files is to avoid the parser initialization costs. Reuse the same XML parser instance for all the files.




回答2:


JDOM 2.0.0 addresses a number of performance issues. One of them is directly related to the 'tight loop' processing of XML files.

Have a look at:

http://hunterhacker.github.com/jdom/jdom2/apidocs/org/jdom2/input/sax/package-summary.html

You should do something like:

SAXBuilder saxbuilder = new SAXBuilder();
saxbuilder.setVariousConfigurations()
SAXEngine saxengine = saxbuilder.buildEnine();

while(hasfile) {
  processXML(saxengine, nextfile);
}

Using the SAXEngine concept in JDOM 2.0.0 will completely eliminate the setup of the SAX-parsing infrastructure. That setup time accounts for a huge proprotion of overall procesing.

While you may still be running at 100%, yu will find your throughput will likely more than double....



来源:https://stackoverflow.com/questions/10116891/jdom-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!