You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by sn...@apache.org on 2002/11/20 22:54:26 UTC
cvs commit: xml-soap/java/src/org/apache/soap/util/xml XMLParserUtils.java
snichol 2002/11/20 13:54:25
Modified: java/src/org/apache/soap/rpc Call.java
java/src/org/apache/soap/server/http RPCRouterServlet.java
java/src/org/apache/soap/util/xml XMLParserUtils.java
Log:
Submitted by: Pavel Ausianik <Pa...@epam.com>
Please see what I propose to solve problem with many allocated
DocumentBuilders.
Other classes were DocumentBuilder is used can be easily adopted in the same
way as Call is.
See thread at http://marc.theaimsgroup.com/?l=soap-dev&m=103582304223623&w=2
for discussion of document builder pooling.
Revision Changes Path
1.24 +10 -4 xml-soap/java/src/org/apache/soap/rpc/Call.java
Index: Call.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/rpc/Call.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Call.java 20 Nov 2002 21:34:42 -0000 1.23
+++ Call.java 20 Nov 2002 21:54:25 -0000 1.24
@@ -90,7 +90,6 @@
*/
public class Call extends RPCMessage
{
- private DocumentBuilder xdb;
private SOAPMappingRegistry smr = null;
private SOAPTransport st = null;;
private int to = 0;
@@ -452,8 +451,15 @@
}
// if the DOM parser hasn't been created yet, do it now
- if (xdb == null)
- xdb = XMLParserUtils.getXMLDocBuilder();
- return xdb.parse(input);
+ DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilderFromPool();
+ Document doc = null;
+ // if the DOM parser hasn't been created yet, do it now
+ try {
+ doc = xdb.parse(input);
+ }
+ finally {
+ XMLParserUtils.returnDocumentBuilderToPool(xdb);
+ }
+ return doc;
}
}
1.44 +14 -10 xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java
Index: RPCRouterServlet.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- RPCRouterServlet.java 20 Nov 2002 21:34:42 -0000 1.43
+++ RPCRouterServlet.java 20 Nov 2002 21:54:25 -0000 1.44
@@ -307,17 +307,21 @@
// EnvelopeEditor
// Note: XMLParser that is specified by init-param isused in
// this process.
- DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
+ DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilderFromPool();
- callEnv =
- ServerHTTPUtils.readEnvelopeFromRequest(xdb,
- req.getContentType(),
- req.getContentLength(),
- req.getInputStream(),
- editor,
- res,
- reqCtx,
- ServerHTTPUtils.getHeaders(req));
+ try {
+ callEnv =
+ ServerHTTPUtils.readEnvelopeFromRequest(xdb,
+ req.getContentType(),
+ req.getContentLength(),
+ req.getInputStream(),
+ editor,
+ res,
+ reqCtx,
+ ServerHTTPUtils.getHeaders(req));
+ } finally {
+ XMLParserUtils.returnDocumentBuilderToPool(xdb);
+ }
if (callEnv == null)
return;
call = RPCRouter.extractCallFromEnvelope(serviceManager, callEnv,
1.8 +38 -12 xml-soap/java/src/org/apache/soap/util/xml/XMLParserUtils.java
Index: XMLParserUtils.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/xml/XMLParserUtils.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XMLParserUtils.java 30 Oct 2002 02:43:04 -0000 1.7
+++ XMLParserUtils.java 20 Nov 2002 21:54:25 -0000 1.8
@@ -57,7 +57,8 @@
package org.apache.soap.util.xml;
-import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
@@ -73,7 +74,7 @@
*/
public class XMLParserUtils {
private static DocumentBuilderFactory dbf = null;
- private static HashMap docBuilderTable = new HashMap ();
+ private static List allocatedBuildersList = new ArrayList(10);
static {
// Create a default instance.
@@ -167,20 +168,45 @@
*/
synchronized public static DocumentBuilder getXMLDocBuilder()
throws IllegalArgumentException {
- // if a document builder has already been created for this thread
- // then just reuse that. otherwise create a new one and remember it.
- Thread t = Thread.currentThread ();
- DocumentBuilder db = (DocumentBuilder) docBuilderTable.get (t);
- if (db != null) {
- return db;
- } else {
try {
- db = dbf.newDocumentBuilder();
- docBuilderTable.put (t, db);
- return db;
+ return dbf.newDocumentBuilder();
} catch (ParserConfigurationException pce) {
throw new IllegalArgumentException(pce.toString());
}
}
+
+
+ /**
+ * Use this method to get a JAXP document builder.
+ * This method either returns a previosly allocated DocumentBuilder
+ * or creates a namespace aware, nonvalidating
+ * instance of the XML parser.
+ *
+ * @return DocumentBuilder an instance of a document builder,
+ * or null if a ParserConfigurationException was thrown.
+ */
+ synchronized public static DocumentBuilder getXMLDocBuilderFromPool() {
+ // First check if we have DocBuider available
+ DocumentBuilder builder = null;
+ int size = allocatedBuildersList.size();
+ if ( size > 0) {
+ builder = (DocumentBuilder)allocatedBuildersList.get(size-1);
+ allocatedBuildersList.remove(size-1);
+ } else
+ // Not available - create a new DocumentBuilder
+ builder = XMLParserUtils.getXMLDocBuilder();
+
+ return builder;
+ }
+
+ /**
+ * Return a JAXP document builder, previosly allocated by method
+ * getXMLDocBuilderFromPool() for further reuse
+ *
+ * @param builder a DocumentBuilder to release
+ */
+ synchronized public static void returnDocumentBuilderToPool(DocumentBuilder builder) {
+ if (builder != null)
+ allocatedBuildersList.add(builder);
}
}
Re: cvs commit: xml-soap/java/src/org/apache/soap/util/xml
XMLParserUtils.java
Posted by Scott Nichol <sn...@scottnichol.com>.
Pavel,
I committed this code for now.
I believe the only outstanding patch submission from you is
SOAPMappingRegistry. I know it's hard to believe, but I will get to it
eventually!
Thanks for all the work on the MIME stuff. It is a great performance
boost.
Scott Nichol
----- Original Message -----
From: <sn...@apache.org>
To: <xm...@apache.org>
Sent: Wednesday, November 20, 2002 4:54 PM
Subject: cvs commit: xml-soap/java/src/org/apache/soap/util/xml
XMLParserUtils.java
> snichol 2002/11/20 13:54:25
>
> Modified: java/src/org/apache/soap/rpc Call.java
> java/src/org/apache/soap/server/http
RPCRouterServlet.java
> java/src/org/apache/soap/util/xml XMLParserUtils.java
> Log:
> Submitted by: Pavel Ausianik <Pa...@epam.com>
>
> Please see what I propose to solve problem with many allocated
> DocumentBuilders.
> Other classes were DocumentBuilder is used can be easily adopted in
the same
> way as Call is.
>
> See thread at
http://marc.theaimsgroup.com/?l=soap-dev&m=103582304223623&w=2
> for discussion of document builder pooling.
>
> Revision Changes Path
> 1.24 +10 -4 xml-soap/java/src/org/apache/soap/rpc/Call.java
>
> Index: Call.java
> ===================================================================
> RCS file:
/home/cvs/xml-soap/java/src/org/apache/soap/rpc/Call.java,v
> retrieving revision 1.23
> retrieving revision 1.24
> diff -u -r1.23 -r1.24
> --- Call.java 20 Nov 2002 21:34:42 -0000 1.23
> +++ Call.java 20 Nov 2002 21:54:25 -0000 1.24
> @@ -90,7 +90,6 @@
> */
> public class Call extends RPCMessage
> {
> - private DocumentBuilder xdb;
> private SOAPMappingRegistry smr = null;
> private SOAPTransport st = null;;
> private int to = 0;
> @@ -452,8 +451,15 @@
> }
>
> // if the DOM parser hasn't been created yet, do it now
> - if (xdb == null)
> - xdb = XMLParserUtils.getXMLDocBuilder();
> - return xdb.parse(input);
> + DocumentBuilder xdb =
XMLParserUtils.getXMLDocBuilderFromPool();
> + Document doc = null;
> + // if the DOM parser hasn't been created yet, do it now
> + try {
> + doc = xdb.parse(input);
> + }
> + finally {
> + XMLParserUtils.returnDocumentBuilderToPool(xdb);
> + }
> + return doc;
> }
> }
>
>
>
> 1.44 +14 -10
xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java
>
> Index: RPCRouterServlet.java
> ===================================================================
> RCS file:
/home/cvs/xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet
.java,v
> retrieving revision 1.43
> retrieving revision 1.44
> diff -u -r1.43 -r1.44
> --- RPCRouterServlet.java 20 Nov 2002 21:34:42 -0000 1.43
> +++ RPCRouterServlet.java 20 Nov 2002 21:54:25 -0000 1.44
> @@ -307,17 +307,21 @@
> // EnvelopeEditor
> // Note: XMLParser that is specified by init-param isused
in
> // this process.
> - DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
> + DocumentBuilder xdb =
XMLParserUtils.getXMLDocBuilderFromPool();
>
> - callEnv =
> - ServerHTTPUtils.readEnvelopeFromRequest(xdb,
> -
req.getContentType(),
> -
req.getContentLength(),
> -
req.getInputStream(),
> - editor,
> - res,
> - reqCtx,
> -
ServerHTTPUtils.getHeaders(req));
> + try {
> + callEnv =
> + ServerHTTPUtils.readEnvelopeFromRequest(xdb,
> +
req.getContentType(),
> +
req.getContentLength(),
> +
req.getInputStream(),
> + editor,
> + res,
> + reqCtx,
> +
ServerHTTPUtils.getHeaders(req));
> + } finally {
> + XMLParserUtils.returnDocumentBuilderToPool(xdb);
> + }
> if (callEnv == null)
> return;
> call = RPCRouter.extractCallFromEnvelope(serviceManager,
callEnv,
>
>
>
> 1.8 +38 -12
xml-soap/java/src/org/apache/soap/util/xml/XMLParserUtils.java
>
> Index: XMLParserUtils.java
> ===================================================================
> RCS file:
/home/cvs/xml-soap/java/src/org/apache/soap/util/xml/XMLParserUtils.java
,v
> retrieving revision 1.7
> retrieving revision 1.8
> diff -u -r1.7 -r1.8
> --- XMLParserUtils.java 30 Oct 2002 02:43:04 -0000 1.7
> +++ XMLParserUtils.java 20 Nov 2002 21:54:25 -0000 1.8
> @@ -57,7 +57,8 @@
>
> package org.apache.soap.util.xml;
>
> -import java.util.HashMap;
> +import java.util.List;
> +import java.util.ArrayList;
> import javax.xml.parsers.*;
> import org.xml.sax.*;
> import org.xml.sax.helpers.*;
> @@ -73,7 +74,7 @@
> */
> public class XMLParserUtils {
> private static DocumentBuilderFactory dbf = null;
> - private static HashMap docBuilderTable = new HashMap ();
> + private static List allocatedBuildersList = new ArrayList(10);
>
> static {
> // Create a default instance.
> @@ -167,20 +168,45 @@
> */
> synchronized public static DocumentBuilder getXMLDocBuilder()
> throws IllegalArgumentException {
> - // if a document builder has already been created for this
thread
> - // then just reuse that. otherwise create a new one and
remember it.
> - Thread t = Thread.currentThread ();
> - DocumentBuilder db = (DocumentBuilder) docBuilderTable.get (t);
> - if (db != null) {
> - return db;
> - } else {
> try {
> - db = dbf.newDocumentBuilder();
> - docBuilderTable.put (t, db);
> - return db;
> + return dbf.newDocumentBuilder();
> } catch (ParserConfigurationException pce) {
> throw new IllegalArgumentException(pce.toString());
> }
> }
> +
> +
> + /**
> + * Use this method to get a JAXP document builder.
> + * This method either returns a previosly allocated
DocumentBuilder
> + * or creates a namespace aware, nonvalidating
> + * instance of the XML parser.
> + *
> + * @return DocumentBuilder an instance of a document builder,
> + * or null if a ParserConfigurationException was thrown.
> + */
> + synchronized public static DocumentBuilder
getXMLDocBuilderFromPool() {
> + // First check if we have DocBuider available
> + DocumentBuilder builder = null;
> + int size = allocatedBuildersList.size();
> + if ( size > 0) {
> + builder =
(DocumentBuilder)allocatedBuildersList.get(size-1);
> + allocatedBuildersList.remove(size-1);
> + } else
> + // Not available - create a new DocumentBuilder
> + builder = XMLParserUtils.getXMLDocBuilder();
> +
> + return builder;
> + }
> +
> + /**
> + * Return a JAXP document builder, previosly allocated by method
> + * getXMLDocBuilderFromPool() for further reuse
> + *
> + * @param builder a DocumentBuilder to release
> + */
> + synchronized public static void
returnDocumentBuilderToPool(DocumentBuilder builder) {
> + if (builder != null)
> + allocatedBuildersList.add(builder);
> }
> }
>
>
>
>
> --
> To unsubscribe, e-mail: <ma...@xml.apache.org>
> For additional commands, e-mail: <ma...@xml.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>
Re: cvs commit: xml-soap/java/src/org/apache/soap/util/xml
XMLParserUtils.java
Posted by Scott Nichol <sn...@scottnichol.com>.
Pavel,
I committed this code for now.
I believe the only outstanding patch submission from you is
SOAPMappingRegistry. I know it's hard to believe, but I will get to it
eventually!
Thanks for all the work on the MIME stuff. It is a great performance
boost.
Scott Nichol
----- Original Message -----
From: <sn...@apache.org>
To: <xm...@apache.org>
Sent: Wednesday, November 20, 2002 4:54 PM
Subject: cvs commit: xml-soap/java/src/org/apache/soap/util/xml
XMLParserUtils.java
> snichol 2002/11/20 13:54:25
>
> Modified: java/src/org/apache/soap/rpc Call.java
> java/src/org/apache/soap/server/http
RPCRouterServlet.java
> java/src/org/apache/soap/util/xml XMLParserUtils.java
> Log:
> Submitted by: Pavel Ausianik <Pa...@epam.com>
>
> Please see what I propose to solve problem with many allocated
> DocumentBuilders.
> Other classes were DocumentBuilder is used can be easily adopted in
the same
> way as Call is.
>
> See thread at
http://marc.theaimsgroup.com/?l=soap-dev&m=103582304223623&w=2
> for discussion of document builder pooling.
>
> Revision Changes Path
> 1.24 +10 -4 xml-soap/java/src/org/apache/soap/rpc/Call.java
>
> Index: Call.java
> ===================================================================
> RCS file:
/home/cvs/xml-soap/java/src/org/apache/soap/rpc/Call.java,v
> retrieving revision 1.23
> retrieving revision 1.24
> diff -u -r1.23 -r1.24
> --- Call.java 20 Nov 2002 21:34:42 -0000 1.23
> +++ Call.java 20 Nov 2002 21:54:25 -0000 1.24
> @@ -90,7 +90,6 @@
> */
> public class Call extends RPCMessage
> {
> - private DocumentBuilder xdb;
> private SOAPMappingRegistry smr = null;
> private SOAPTransport st = null;;
> private int to = 0;
> @@ -452,8 +451,15 @@
> }
>
> // if the DOM parser hasn't been created yet, do it now
> - if (xdb == null)
> - xdb = XMLParserUtils.getXMLDocBuilder();
> - return xdb.parse(input);
> + DocumentBuilder xdb =
XMLParserUtils.getXMLDocBuilderFromPool();
> + Document doc = null;
> + // if the DOM parser hasn't been created yet, do it now
> + try {
> + doc = xdb.parse(input);
> + }
> + finally {
> + XMLParserUtils.returnDocumentBuilderToPool(xdb);
> + }
> + return doc;
> }
> }
>
>
>
> 1.44 +14 -10
xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java
>
> Index: RPCRouterServlet.java
> ===================================================================
> RCS file:
/home/cvs/xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet
.java,v
> retrieving revision 1.43
> retrieving revision 1.44
> diff -u -r1.43 -r1.44
> --- RPCRouterServlet.java 20 Nov 2002 21:34:42 -0000 1.43
> +++ RPCRouterServlet.java 20 Nov 2002 21:54:25 -0000 1.44
> @@ -307,17 +307,21 @@
> // EnvelopeEditor
> // Note: XMLParser that is specified by init-param isused
in
> // this process.
> - DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
> + DocumentBuilder xdb =
XMLParserUtils.getXMLDocBuilderFromPool();
>
> - callEnv =
> - ServerHTTPUtils.readEnvelopeFromRequest(xdb,
> -
req.getContentType(),
> -
req.getContentLength(),
> -
req.getInputStream(),
> - editor,
> - res,
> - reqCtx,
> -
ServerHTTPUtils.getHeaders(req));
> + try {
> + callEnv =
> + ServerHTTPUtils.readEnvelopeFromRequest(xdb,
> +
req.getContentType(),
> +
req.getContentLength(),
> +
req.getInputStream(),
> + editor,
> + res,
> + reqCtx,
> +
ServerHTTPUtils.getHeaders(req));
> + } finally {
> + XMLParserUtils.returnDocumentBuilderToPool(xdb);
> + }
> if (callEnv == null)
> return;
> call = RPCRouter.extractCallFromEnvelope(serviceManager,
callEnv,
>
>
>
> 1.8 +38 -12
xml-soap/java/src/org/apache/soap/util/xml/XMLParserUtils.java
>
> Index: XMLParserUtils.java
> ===================================================================
> RCS file:
/home/cvs/xml-soap/java/src/org/apache/soap/util/xml/XMLParserUtils.java
,v
> retrieving revision 1.7
> retrieving revision 1.8
> diff -u -r1.7 -r1.8
> --- XMLParserUtils.java 30 Oct 2002 02:43:04 -0000 1.7
> +++ XMLParserUtils.java 20 Nov 2002 21:54:25 -0000 1.8
> @@ -57,7 +57,8 @@
>
> package org.apache.soap.util.xml;
>
> -import java.util.HashMap;
> +import java.util.List;
> +import java.util.ArrayList;
> import javax.xml.parsers.*;
> import org.xml.sax.*;
> import org.xml.sax.helpers.*;
> @@ -73,7 +74,7 @@
> */
> public class XMLParserUtils {
> private static DocumentBuilderFactory dbf = null;
> - private static HashMap docBuilderTable = new HashMap ();
> + private static List allocatedBuildersList = new ArrayList(10);
>
> static {
> // Create a default instance.
> @@ -167,20 +168,45 @@
> */
> synchronized public static DocumentBuilder getXMLDocBuilder()
> throws IllegalArgumentException {
> - // if a document builder has already been created for this
thread
> - // then just reuse that. otherwise create a new one and
remember it.
> - Thread t = Thread.currentThread ();
> - DocumentBuilder db = (DocumentBuilder) docBuilderTable.get (t);
> - if (db != null) {
> - return db;
> - } else {
> try {
> - db = dbf.newDocumentBuilder();
> - docBuilderTable.put (t, db);
> - return db;
> + return dbf.newDocumentBuilder();
> } catch (ParserConfigurationException pce) {
> throw new IllegalArgumentException(pce.toString());
> }
> }
> +
> +
> + /**
> + * Use this method to get a JAXP document builder.
> + * This method either returns a previosly allocated
DocumentBuilder
> + * or creates a namespace aware, nonvalidating
> + * instance of the XML parser.
> + *
> + * @return DocumentBuilder an instance of a document builder,
> + * or null if a ParserConfigurationException was thrown.
> + */
> + synchronized public static DocumentBuilder
getXMLDocBuilderFromPool() {
> + // First check if we have DocBuider available
> + DocumentBuilder builder = null;
> + int size = allocatedBuildersList.size();
> + if ( size > 0) {
> + builder =
(DocumentBuilder)allocatedBuildersList.get(size-1);
> + allocatedBuildersList.remove(size-1);
> + } else
> + // Not available - create a new DocumentBuilder
> + builder = XMLParserUtils.getXMLDocBuilder();
> +
> + return builder;
> + }
> +
> + /**
> + * Return a JAXP document builder, previosly allocated by method
> + * getXMLDocBuilderFromPool() for further reuse
> + *
> + * @param builder a DocumentBuilder to release
> + */
> + synchronized public static void
returnDocumentBuilderToPool(DocumentBuilder builder) {
> + if (builder != null)
> + allocatedBuildersList.add(builder);
> }
> }
>
>
>
>
> --
> To unsubscribe, e-mail: <ma...@xml.apache.org>
> For additional commands, e-mail: <ma...@xml.apache.org>
>
>