axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/utils XMLUtils.java
Date Tue, 02 Oct 2001 17:50:23 GMT
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