I'm running a multithreaded application in which each thread is a heavy docx4j user.
Profiling the application, I'm noticing some contention around XmlUtils.getNewDocumentBuilder() which is blocking the static instance of DocumentBuilderFactory.
From what I understand from https://jaxp.java.net/docs/spec/html/#p ... ead-safety, the DocumentBuilderFactory.newDocumentBuilder() method should be threadsafe.
It is expected that the newSAXParser method of a SAXParserFactory implementation, the newDocumentBuilder method of a DocumentBuilderFactory and the newTransformer method of a TransformerFactory will be thread safe without side effects...
Is there a reason I'm missing for this synchronization?
Letting it go would quicken things (in these cases).
On the same note, regarding the comments in XmlUtils on sharing DocumentBuilders, ThreadLocal seems like the optimal solution.. Not sure though how much it would save as I I'm not sure how much it costs to create a new DocumentBuilder.
Cheers,
Roded
N.B. If Github is the right place for this, do tell and I'll move the discussion.