Parsing multiple XML files using multithreading with SAXParser

半腔热情 提交于 2019-12-12 04:05:31

问题


I have a timer which checks for new XML files on the file system and parses them. XML files can get large(5GB), so i am using sax parser. To increase the productivity, i wrote a multithreading programm with executer service.

XML files can belong to different sources. For each source is being a thread created and in this thread XML files parsed which belong to the source. In every thread a new SaxParserFactory and for every XML file a new SaxParser created.

The problem is that different parser kill each others process. When i check the parse results, i notice that some of the XML's haven't been parsed completely. The parser quits halfway and doesn't throw any exception. I dont have the problem when the XML files is being parsed in single thread.

Now i am not sure, if the SaxParserFactory and SaxParser really create new instances.

Do you guys have any idea what might cause this?

SAXParser parser = factory.newSAXParser();
AccountSaxHandler saxHandler = new AccountSaxHandler();
parser.parse(new File(localFilePath), saxHandler);

来源:https://stackoverflow.com/questions/31312988/parsing-multiple-xml-files-using-multithreading-with-saxparser

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