We've got an application in production on Tomcat 4.1.30 (SDK 1.4.2).
The application works fine in test. In production, however, there seems to be some kind of degradation.
When there is a certain load (not even very high), the following occurs:
These 2 lines (in several classes, JasperReports as well as our own code):
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
documentBuilder = factory.newDocumentBuilder();
Start to work with the wrong class:
(the XML parser of Axis2)
instead of the wanted class:
Both classes are in our classpath, but for some reason this problem only occurs in production after a period of uptime.
This gives NullPointerExceptions.
What should we do to avoid this ?
Is it the classloader of tomcat going strange ?
Any help would be appreciated.
As per the Java API:
DocumentBuilderFactory: [...]An implementation of the DocumentBuilderFactory class is NOT guaranteed to be thread safe. It is up to the user application to make sure about the use of the DocumentBuilderFactory from more than one thread. Alternatively the application can have one instance of the DocumentBuilderFactory per thread. An application can use the same instance of the factory to obtain one or more instances of the DocumentBuilder provided the instance of the factory isn't being used in more than one thread at a time.
1)Can you perhaps load the documentBuilder through a singleton (or a servlet init)?
2)Ensure that the appropriate library is in the web-inf/lib
I am sure you may be able to replicate this problem with a simple load test on your dev env as well
thanks for your input.
Both classes (the axis2 one and the xerces one) are in web-inf/lib
Is threadsafeness the problem here ? Why would it try to create another documentbuilder as a result of concurrency ?