Hi Sven,
Have you tried reusing a single TransformerFactory to see if it is the
many TransformerFactories that somehow makes things slow ?
- I think the common pattern is to have a single factory to create all
Transforms.
Christoffer Bruun
Den 3/1/2017 kl. 10:27 AM skrev Sven Richter:
I have a problem where I do not know what the root cause actually is.
I also asked already in different places without getting an answer.
I create an instance of javax.xml.transform.TransformerFactory and
directly afterwards I parse a xsltSource:
protected synchronized Transformer getTransformer(Source xsltSource)
throws TransformerConfigurationException {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(xsltSource);
return transformer;
}
I am using the com.sun.org.apache.xalan.internal.xsltc.trax.Trans
formerFactoryImpl com.sun.org.apache.xalan.internal.xsltc.trax.Trans
formerImpl classes.
Which are the ones provided by the JDK.
Now I have a test that is part of the test suite. When I run that test
standalone the code above takes around 1ms constantly.
When I run that test as part of my test suite it takes longer. This
happens as well in eclipse as with gradle. The duration rises linear
with the amount of tests that run before.
Its orders of magnitudes slower, like 10 - 1000 times, depending on
how much tests run before that specific test.
Using a cached instance of the TransfomerFactory will cut the time the
test takes in half. But the symptom remains the same.
I have been profiling it, but dont see anything suspicious, except the
the test takes longer.
My first assumption was it had directly to do with the number of
loaded classes, which it does not. Loading classes arbitrarily does
not change the time the test needs.
Next I added the saxon parser and specifically used that one, but the
symptom remains the same.
Also I figured out I have the same problem with this line of code:
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
Any ideas what might be the cause here?
Thanks,
Sven