santiagopg 2002/09/23 11:21:54
Modified: java/src/org/apache/xalan/xsltc/trax
TransformerFactoryImpl.java
Log:
Return a fresh XMLReader for each call to getXMLReader(). Returning the
same instance is incorrect in multi-threaded apps where a single
transformer factory is shared by all threads.
Revision Changes Path
1.47 +14 -10
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
Index: TransformerFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- TransformerFactoryImpl.java 17 Sep 2002 22:08:06 -0000 1.46
+++ TransformerFactoryImpl.java 23 Sep 2002 18:21:54 -0000 1.47
@@ -157,9 +157,9 @@
private int _indentNumber = -1;
/**
- * A reference to an XML reader for parsing.
+ * A reference to a SAXParserFactory.
*/
- private XMLReader _xmlReader = null;
+ private SAXParserFactory _parserFactory = null;
/**
* javax.xml.transform.sax.TransformerFactory implementation.
@@ -724,13 +724,17 @@
return null;
}
- public XMLReader getXMLReader() throws Exception {
- if (_xmlReader == null) {
- final SAXParserFactory pfactory
- = SAXParserFactory.newInstance();
- pfactory.setNamespaceAware(true);
- _xmlReader = pfactory.newSAXParser().getXMLReader();
+ /**
+ * This method is synchronized to allow instances of this class to
+ * be shared among threads. A tranformer object will call this
+ * method to get an XMLReader.
+ */
+ public synchronized XMLReader getXMLReader() throws Exception {
+ // First check if factory is instantiated
+ if (_parserFactory == null) {
+ _parserFactory = SAXParserFactory.newInstance();
+ _parserFactory.setNamespaceAware(true);
}
- return _xmlReader;
+ return _parserFactory.newSAXParser().getXMLReader();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]