Personally, I would argue that the Xerces docs are wrong, but it
is probably driven by fear and uncertainty. Parsers should always
be reusable and there is certainly a lot of code in the Xerces
implementation that is trying to make that so. I am not aware of
any problem reported of a parser not being reusable that was not
considered a defect. Are people running into problems and not
reporting them, or is "fear and uncertainty" winning for no good
reason?
Regards,
Glenn
Sam
Ruby/Raleigh/I To: [EMAIL PROTECTED]
BM@IBMUS cc: [EMAIL PROTECTED]
Subject: Warning! Re: cvs commit:
10/02/2001 xml-axis/java/src/org/apache/axis/utils
XMLUtils.java
02:15 PM
Please respond
to
xerces-j-dev
Comments?
- Sam Ruby
---------------------- Forwarded by Sam Ruby/Raleigh/IBM on 10/02/2001
02:13 PM ---------------------------
Berin Loritsch <[EMAIL PROTECTED]> on 10/02/2001 02:05:01 PM
Please respond to [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
cc: [EMAIL PROTECTED]
Subject: Warning! Re: cvs commit: xml-axis/java/src/org/apache/axis/utils
XMLUtils.java
We ran into a problem with Xerces that made this unuseable in Cocoon.
According to the Xerces docs, we cannot assume the Parser returned from
SAXParserFactory can be reused. For 90% of the cases, there is no problem,
however we had an Exception 10% of the time. The cause was unknown, but
the problem quickly came to light under load.
Once a Parser threw an exception, it would always throw an exception. This
is not good in a production environment. I don't know if JAXP specs have
been changed to require that the parser be reusable, and the problem we
came accross was in an older Xerces version (whatever was current back
in March/April).
[EMAIL PROTECTED] wrote:
>
> rubys 01/10/02 10:50:23
>
> Modified: java/src/org/apache/axis/encoding
> DeserializationContext.java
> java/src/org/apache/axis/utils XMLUtils.java
> Log:
> Reuse SAX parsers for performance reasons. Measured using OptimizeIt
to
> save nearly 15% overall on an end-to-end local getStockQuote XXX
scenario.
>
> Revision Changes Path
> 1.22 +8 -4
xml-axis/java/src/org/apache/axis/encoding/DeserializationContext.java
>
> Index: DeserializationContext.java
> ===================================================================
> RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializationContext.java,v
> retrieving revision 1.21
> retrieving revision 1.22
> diff -u -r1.21 -r1.22
> --- DeserializationContext.java 2001/09/05 17:22:59 1.21
> +++ DeserializationContext.java 2001/10/02 17:50:22 1.22
> @@ -157,11 +157,15 @@
> if (inputSource != null) {
> SAXParser parser = XMLUtils.getSAXParser();
> try {
> - parser.parse(inputSource, this);
> - } catch (IOException e) {
> - throw new SAXException(e);
> + try {
> + parser.parse(inputSource, this);
> + } catch (IOException e) {
> + throw new SAXException(e);
> + }
> + inputSource = null;
> + } finally {
> + XMLUtils.releaseSAXParser(parser);
> }
> - inputSource = null;
> }
> }
>
>
>
>
> 1.18 +15 -4
xml-axis/java/src/org/apache/axis/utils/XMLUtils.java
>
> Index: XMLUtils.java
> ===================================================================
> RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/utils/XMLUtils.java,v
> retrieving revision 1.17
> retrieving revision 1.18
> diff -u -r1.17 -r1.18
> --- XMLUtils.java 2001/09/10 19:50:42 1.17
> +++ XMLUtils.java 2001/10/02 17:50:23 1.18
> @@ -56,6 +56,7 @@
> package org.apache.axis.utils ;
>
> import java.io.* ;
> +import java.util.Stack;
> import java.util.Properties;
> import org.w3c.dom.* ;
> import javax.xml.parsers.* ;
> @@ -65,6 +66,7 @@
> public class XMLUtils {
> private static DocumentBuilderFactory dbf = init();
> private static SAXParserFactory saxFactory;
> + private static Stack saxParsers = new Stack();
>
> static {
> // Initialize SAX Parser factory defaults
> @@ -149,11 +151,13 @@
> *
> * @return a SAXParser instance.
> */
> - public static SAXParser getSAXParser() {
> - // Might want to cache the parser (on a per-thread basis, as I
don't think
> - // SAX parsers are thread-safe)...
> + public static synchronized SAXParser getSAXParser() {
> try {
> - return saxFactory.newSAXParser();
> + if (saxParsers.empty()) {
> + return saxFactory.newSAXParser();
> + } else {
> + return (SAXParser)saxParsers.pop();
> + }
> } catch (ParserConfigurationException e) {
> e.printStackTrace();
> return null;
> @@ -161,6 +165,13 @@
> se.printStackTrace();
> return null;
> }
> + }
> +
> + /** Return a SAX parser for reuse.
> + * @param SAXParser A SAX parser that is available for reuse
> + */
> + public static synchronized SAXParser releaseSAXParser(SAXParser
parser) {
> + return (SAXParser)saxParsers.push(parser);
> }
>
> public static Document newDocument() {
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]