Is a TransformerFactory thread-safe?
Added by Markus Karg over 11 years ago
I know that this is kind of off-topic as it is a general JAXP question, but to my justification, the official JAXP forum at java.net seems to be dead and I hoped that Michael knows both, the JAXP view and the SAXON view. So please don't mind my posting here. :-)
The JavaDocs of TransformerFactory told explicitly that it is not safe to use a TransformerFactory with multiple threads, but since Java 5 that phrase was removed. So since Java 5 the docs only say that Transformers are not thread-safe.
So does that mean that any JAXP implementation provides a thread-safe since Java 5?
And is SAXON's TransformerFactory in particular thread-safe?
Replies (2)
RE: Is a TransformerFactory thread-safe? - Added by Michael Kay over 11 years ago
The Saxon TransformerFactory and the underlying Configuration object is designed to be thread-safe in a technical sense, but I would avoid changing some properties while the Configuration is in use; for example changing the NamePool in mid-flight would typically be disastrous. This is not so much a thread-safety issue as a consistency requirement; for some configuration properties, there is an assumption that the configuration state during stylesheet compilation is the same as the state during stylesheet execution.
Generally I would recommend setting up the Configuration in one thread and then using it in read-only mode in as many threads as you like.
RE: Is a TransformerFactory thread-safe? - Added by Markus Karg over 11 years ago
Great to hear, thank you for this explanation! In fact what I'd like to do is to set up TransforerFactory.getInstance() once and then in each thread simply do SINGLETON_FACTORY.getTransformer() to do the actual work (so the factory is read-only effectively). :-)
Please register to reply