8

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!

Leo
  • 6,480
  • 4
  • 37
  • 52
Chandra Sekar
  • 10,683
  • 3
  • 39
  • 54

1 Answers1

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.

Chandra Sekar
  • 10,683
  • 3
  • 39
  • 54