Is XMLInputFactory thread-safe?
Asked Answered
O

1

9

When profiling my application, I noticed that creating instances of XMLInputFactory over and over is very expensive. Is it safe to share its instances across multiple threads?

The javadoc doesn't say anything about its thread-safety and searching the internet doesn't give a definite answer!

Ophite answered 7/2, 2014 at 17:39 Comment(8)
Yes, it is thread safe.Bareheaded
@Bareheaded Can you point me to some documentation or resource which discusses this?Ophite
maybe it's not issues.apache.org/jira/browse/AXIOM-74Rianna
I peeked into OpenJDK sources and just configuration must be synchronized. But I must say, that it may depend upon implementation. XMLInputFactory itself is abstract!Bareheaded
true. @Chandru what JDK are you using?Rianna
not sure about jdk7, but check this out svn.codehaus.org/woodstox/wstx/trunk/release-notes/USAGE - it seems to be for woodstoxRianna
@Rianna Looks like I added my answer at the same time as your comment. Provide it as an answer and I'll accept it.Ophite
Hi, does anyone has an answer on this?Dippold
O
7

I have decided to use Woodstox as the StAX implementation. It is both much faster than the default JDK implementation and explicitly mentions thread safety.

Woodstox factories are thread-safe after configuration phase (calling setProperty()), but not during it. Most importantly, once all configuration is done, calling 'createXMLxxx' methods is fully thread-safe.

Ophite answered 7/2, 2014 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.