I'd like to know which objects can be reused (in the same or different document) when using the Java API for XML processing, JAXP:
DocumentBuilderFactory
DocumentBuilder
XPath
Node
(EDIT: I forgot that this has to be implemented in my own code, sorry)ErrorHandler
Is it recommended to cache those objects or do the JAXP implementations already cache them?
Is the (re)use of those objects thread-safe?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- Illegal to have multiple roots (start tag in epilo
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Reuse
In the same thread those objects can and should be reused. For example you can use the DocumentBuilder to parse multiple documents.
Thread Safety
DocumentBuilderFactory used to explicity state it was not thread safe, I believe this is still true:
From Stack Overflow, DocumentBuilder does not appear to be thread safe either. However in Java SE 5 a reset method was added to allow you to reuse DocumentBuilders:
XPath is not thread safe, from the Javadoc
Node is not thread safe, from Xerces website
ErrorHandler is an interface, so it is up to your implementation of that interface to ensure thread-safety. For pointers on thread-safety you could start here: