You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2004/10/14 17:32:22 UTC

cvs commit: ws-axis/java/src/org/apache/axis/utils XMLUtils.java

dims        2004/10/14 08:32:22

  Modified:    java/src/org/apache/axis/utils XMLUtils.java
  Log:
  Fix for AXIS-1597 - Reponse time increases with load for axis
  from gunsnroz@hotmail.com and peters@fast.fujitsu.com.au
  
  Revision  Changes    Path
  1.97      +56 -11    ws-axis/java/src/org/apache/axis/utils/XMLUtils.java
  
  Index: XMLUtils.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/utils/XMLUtils.java,v
  retrieving revision 1.96
  retrieving revision 1.97
  diff -u -r1.96 -r1.97
  --- XMLUtils.java	19 Jul 2004 03:03:33 -0000	1.96
  +++ XMLUtils.java	14 Oct 2004 15:32:22 -0000	1.97
  @@ -81,6 +81,7 @@
           "javax.xml.parsers.SAXParserFactory";
   
       private static DocumentBuilderFactory dbf = getDOMFactory();
  +    private static Stack                  documentBuilders = new Stack(); 
       private static SAXParserFactory       saxFactory;
       private static Stack                  saxParsers = new Stack();
       private static DefaultHandler doNothingContentHandler = new DefaultHandler();
  @@ -205,6 +206,36 @@
           }
           return( dbf );
       }
  +
  +    /**
  +     * Gets a DocumentBuilder
  +     * @return DocumentBuilder
  +     * @throws ParserConfigurationException
  +     */ 
  +    public static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
  +        synchronized (documentBuilders) {
  +            if (!documentBuilders.empty()) {
  +                return (DocumentBuilder) documentBuilders.pop();
  +            }
  +        }
  +        DocumentBuilder db = null;
  +        synchronized (dbf) {
  +            db = dbf.newDocumentBuilder();
  +        }
  +        return db;
  +    }
  +
  +    /**
  +     * Releases a DocumentBuilder
  +     * @param db
  +     */ 
  +    public static void releaseDocumentBuilder(DocumentBuilder db) {
  +        synchronized (documentBuilders) {
  +            db.setErrorHandler(null); // setting implementation default
  +            db.setEntityResolver(null); // setting implementation default
  +            documentBuilders.push(db);
  +        }
  +    }
       
       private static boolean tryReset= true;
   
  @@ -265,14 +296,22 @@
       }
       /**
        * Get an empty new Document
  +     *
        * @return Document
        * @throws ParserConfigurationException if construction problems occur
        */
  -    public static Document newDocument() 
  -         throws ParserConfigurationException
  -    {
  -        synchronized (dbf) {
  -            return dbf.newDocumentBuilder().newDocument();
  +    public static Document newDocument()
  +            throws ParserConfigurationException {
  +        DocumentBuilder db = null;
  +        try {
  +            db = getDocumentBuilder();
  +            Document doc = db.newDocument();
  +            releaseDocumentBuilder(db);
  +            return doc;
  +        } finally {
  +            if (db != null) {
  +                releaseDocumentBuilder(db);
  +            }
           }
       }
   
  @@ -286,13 +325,19 @@
       public static Document newDocument(InputSource inp)
           throws ParserConfigurationException, SAXException, IOException
       {
  -        DocumentBuilder db;
  -        synchronized (dbf) {
  -            db = dbf.newDocumentBuilder();
  +        DocumentBuilder db = null;
  +        try {
  +            db = getDocumentBuilder();
  +            db.setEntityResolver(new DefaultEntityResolver());
  +            db.setErrorHandler(new ParserErrorHandler());
  +            Document doc = db.parse(inp);
  +            releaseDocumentBuilder(db);
  +            return doc;
  +        } finally {
  +            if (db != null) {
  +                releaseDocumentBuilder(db);
  +            }
           }
  -        db.setEntityResolver(new DefaultEntityResolver());
  -        db.setErrorHandler( new ParserErrorHandler() );
  -        return( db.parse( inp ) );
       }
   
       /**