axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sam Ruby" <ru...@us.ibm.com>
Subject Warning! Re: cvs commit: xml-axis/java/src/org/apache/axis/utils XMLUtils.java
Date Tue, 02 Oct 2001 18:15:36 GMT
Comments?

- Sam Ruby
---------------------- Forwarded by Sam Ruby/Raleigh/IBM on 10/02/2001
02:13 PM ---------------------------

Berin Loritsch <bloritsch@apache.org> on 10/02/2001 02:05:01 PM

Please respond to axis-dev@xml.apache.org

To:   axis-dev@xml.apache.org
cc:   xml-axis-cvs@apache.org
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).

rubys@apache.org 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() {
>
>
>



Mime
View raw message