Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] XSLTTransform.setNodeFactory() thread safety

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] XSLTTransform.setNodeFactory() thread safety
  • Date: Tue, 7 Sep 2004 13:58:22 -0700

There seems to be a potential problem wrt. thread safety of XSLTTransform.setNodeFactory().
Assume an app drives XSLTransform.transform concurrently from multiple threads and it uses a custom node factory that is stateful (keeps track of current state for non-trivial streaming transforms).
Without additional synchronization measures the node factory would run into race conditions.

To make it thread safe the most reasonable approach is *not* to have the node factory be thread safe (leads to heavy and long lived lock contention) but to have one independent node factory object per thread.
In this case synchronizing on setNodeFactory before each transform() is cumbersome, non-intuitive and error-prone.
If there were a method XSLTransform.transform(Document, NodeFactory) one could provide a new node factory on each invocation and gain thread safety in a straightforward manner.

Another option would be to have an XSLTransform object per thread. That would work around it, but seems counter-intuitive since that would somewhat defeat the purpose of the Templates object. The whole idea of a Templates object is that it is implicitly thread safe and can efficiently be reused many times via the cheap templates.newTransformer() [e.g. XSLTC].

Another option would be to have XSLTransform have a method that creates a NodeFactory on each transform(). Seems too complicated. Yet another option would be to have a NodeFactoryFactory class (creates a NodeFactory). Again seems too complicated for what it's worth.

Thoughts?





Archive powered by MHonArc 2.6.24.

Top of Page