Thanks a lot, Michael ! All of this is true and do not have changed since my last post on this list, but I did forget it... Now, I construct this example to illustrate a java-performance course... the conclusion is "move to Saxon" !

Best regards,
Christophe

Le 06/09/2012 12:25, Michael Kay a écrit :

Oddly, I just suggested to a user on StackOverflow that their problems were caused by DOM's lack of thread-safety:

http://stackoverflow.com/questions/12291840/unknown-error-in-xpath/12297873#12297873

It's worth bearing in mind that quite apart from the lack of thread-safety in DOM, Saxon is typically 5-10 times slower processing a DOM compared with processing its native tree structure. Rebuilding the DOM as a Saxon tree before the transformation starts can sometimes be faster than running Saxon against the DOM directly. Of course even that will need to be synchronized. The DOM spec says that it isn't thread-safe, and the Xerces implementation of the DOM takes this literally - innocent-looking read operations can cause havoc if there are other threads active.

By contrast, all Saxon's native tree implementations are thread-safe, at least if you avoid update operations once the tree has been built.

Michael Kay
Saxonica

On 06/09/2012 07:26, Christophe Marchand wrote:
My problem is solved :
I was giving a DOM document as parameter to the transform, and this DOM document was shared between threads. nodeCloning the document solved the problem, but introduce performance regression...
Grrrr...

Best regards,
Christophe

Le 05/09/2012 15:29, Christophe Marchand a écrit :
Hi all !

now in a new company, I joined back the list.

I have a strange problem, transforming a DOM to a Stream. It seems my DOM do not have a correct structure.
When I run my process in a single thread, I have no problem, but when I use parallel processing, I have this error :

java.lang.NullPointerException
    at org.apache.xerces.dom.ParentNode.nodeListItem(Unknown Source)
    at org.apache.xerces.dom.ParentNode.item(Unknown Source)
    at net.sf.saxon.dom.NodeWrapper$ChildEnumeration.skipFollowingTextNodes(NodeWrapper.java:1166)
    at net.sf.saxon.dom.NodeWrapper$ChildEnumeration.next(NodeWrapper.java:1194)
    at net.sf.saxon.tree.util.Navigator$AxisFilter.next(Navigator.java:879)
    at net.sf.saxon.expr.ContextMappingIterator.next(ContextMappingIterator.java:51)
    at net.sf.saxon.expr.MappingIterator.next(MappingIterator.java:51)
    at net.sf.saxon.expr.GeneralComparison.effectiveBooleanValue(GeneralComparison.java:539)
    at net.sf.saxon.expr.FilterIterator$NonNumeric.matches(FilterIterator.java:182)
    at net.sf.saxon.expr.FilterIterator.getNextMatchingItem(FilterIterator.java:65)
    at net.sf.saxon.expr.FilterIterator.next(FilterIterator.java:44)
    at net.sf.saxon.expr.ContextMappingIterator.next(ContextMappingIterator.java:51)
    at net.sf.saxon.expr.ContextMappingIterator.next(ContextMappingIterator.java:51)
    at net.sf.saxon.value.SequenceExtent.<init>(SequenceExtent.java:103)
    at net.sf.saxon.expr.sort.DocumentOrderIterator.<init>(DocumentOrderIterator.java:30)
    at net.sf.saxon.expr.sort.DocumentSorter.iterate(DocumentSorter.java:96)
    at net.sf.saxon.expr.Atomizer.iterate(Atomizer.java:207)
    at net.sf.saxon.expr.AtomicSequenceConverter.iterate(AtomicSequenceConverter.java:110)
    at net.sf.saxon.functions.StringJoin.evaluateItem(StringJoin.java:71)
    at net.sf.saxon.expr.Expression.evaluateAsString(Expression.java:469)
    at net.sf.saxon.expr.instruct.SimpleNodeConstructor.processLeavingTail(SimpleNodeConstructor.java:180)
    at net.sf.saxon.expr.instruct.ValueOf.processLeavingTail(ValueOf.java:226)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:269)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:269)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.LetExpression.process(LetExpression.java:409)
    at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:387)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:269)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:269)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Choose.processLeavingTail(Choose.java:758)
    at net.sf.saxon.expr.instruct.Template.expand(Template.java:225)
    at net.sf.saxon.expr.instruct.CallTemplate.process(CallTemplate.java:284)
    at net.sf.saxon.expr.instruct.CallTemplate.processLeavingTail(CallTemplate.java:308)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:208)
    at net.sf.saxon.expr.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:368)
    at net.sf.saxon.expr.instruct.ApplyTemplates$ApplyTemplatesPackage.processLeavingTail(ApplyTemplates.java:636)
    at net.sf.saxon.expr.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:340)
    at net.sf.saxon.expr.instruct.ApplyTemplates.apply(ApplyTemplates.java:232)
    at net.sf.saxon.expr.instruct.ApplyTemplates.processLeavingTail(ApplyTemplates.java:196)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:269)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator.java:269)
    at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:208)
    at net.sf.saxon.expr.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:368)
    at net.sf.saxon.trans.StringifyRuleSet.process(StringifyRuleSet.java:54)
    at net.sf.saxon.expr.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:356)
    at net.sf.saxon.Controller.transformDocument(Controller.java:1887)
    at net.sf.saxon.Controller.transform(Controller.java:1737)
    at com.oxiane.perf.java.pdf.PdfRunner.createPdfFromBulletin(PdfRunner.java:134)


My code is :
            DocumentBuilderFactory domFactory = FactoryProvider.getDocumentBuilderFactory();
            DocumentBuilder builder = domFactory.newDocumentBuilder();
            Document dom = builder.parse(new ByteArrayInputStream(data));
...
            String xsltName = elementModel.getXslt();
            Templates tpl = rendererXsltCache.get(xsltName);
            if(tpl==null) {
                File XsltFile = new File(payeModel.getBaseDirectory(),xsltName);
                TransformerFactory tFactory = FactoryProvider.getTransformerFactory();
                tpl = tFactory.newTemplates(new StreamSource(XsltFile));
                rendererXsltCache.put(xsltName, tpl);
            }
            Transformer transformer = tpl.newTransformer();
            transformer.setParameter("repository", repository);
            File targetFile = new File(outputDir, fileName+".pdf");
            OutputStream osXhtml = new FileOutputStream(tmpFile);
            transformer.transform(new DOMSource(dom), new StreamResult(osXhtml));
            osXhtml.flush(); osXhtml.close();


I use Saxon 9.2.

Any idea wil be much appreciated !

Best regards,
Crhistophe


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help 



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help 



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help