Java Jaxb多线程拆开



我要创建一个类,该类应该删除非常巨大的XML文件。

我已经实施了一般的Unmarshalling:

public XMLProcessor(XMLFile file) throws JAXBException, IOException, SAXException {
    JAXBContext jc = JAXBContext.newInstance(Customers.class);
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    File xml = new File(file.getFile().getOriginalFilename());
    file.getFile().transferTo(xml);
    this.customers = (Customers) unmarshaller.unmarshal(xml);
}

它可以正常工作,但是处理100万客户xml花了超过一分钟的时间。

我可以通过创建多个线程并同时删除XML文件的几个部分来改善性能吗?

我应该如何将XML文件分成零件?

您可以向我展示一些我的案件示例代码吗?

尽管我还不能提供完整的解决方案,但我想与您分享我目前在类似问题上实现的方法。我的XML文件结构就像:

<products>
  <product id ="p1">
    <variant id="v1"></variant>
    <variant id="v2"></variant>
  </product>
  <product id ="p2">
    <variant id="v3"></variant>
    <variant id="v4"></variant>
  </product>
</products>

产品和变体可能非常复杂,具有许多属性,列表等。

我当前的方法是使用sax提取单个产品实体的XML-流,然后将其交给新的Unmarshallershaller线程(具有标准的多线程操作,限制为最大线程计数等)。

但是,如果萨克斯(Sax)产生太多的开销(可能会吞噬多线程福利),我仍然没有100%的信心。如果是这种情况,我将尝试直接读取XML-stream,并在开放/关闭标签上对"做出反应。a这不会是XML构造,这是我对最后一个度假胜地的度量

最新更新