Hello,

I have  a question related to this commit. 

What if threads are not reused constantly, but once finished processing
something just discarded? In this case hashmap will prevent both thread and
document builder from be removed by GC.

Another question, what if Call created in one thread, but then reused in
other threads (I myself thought about having pool of Call objects) - in this
case the login of getting DocumentBuilder by current thread will likely
produce errors, which very difficult to debug.

Thanks,
Pavel

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:sanjiva@;apache.org]
> Sent: Monday, October 28, 2002 6:37 PM
> To: [EMAIL PROTECTED]
> Subject: cvs commit: xml-soap/java/src/org/apache/soap/util/xml
> XMLParserUtils.java
> 
> 
> sanjiva     2002/10/28 08:37:02
> 
>   Modified:    java/src/org/apache/soap/util/xml XMLParserUtils.java
>   Log:
>   added logic to share instances of DocumentBuilders on a per-thread
>   basis
>   
>   Revision  Changes    Path
>   1.6       +16 -7     
> 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/XMLParser
> Utils.java,v
>   retrieving revision 1.5
>   retrieving revision 1.6
>   diff -u -r1.5 -r1.6
>   --- XMLParserUtils.java     17 May 2002 18:11:57 -0000      1.5
>   +++ XMLParserUtils.java     28 Oct 2002 16:37:02 -0000      1.6
>   @@ -57,7 +57,7 @@
>    
>    package org.apache.soap.util.xml;
>    
>   -// JAXP packages
>   +import java.util.HashMap;
>    import javax.xml.parsers.*;
>    import org.xml.sax.*;
>    import org.xml.sax.helpers.*;
>   @@ -73,6 +73,7 @@
>     */
>    public class XMLParserUtils {
>      private static DocumentBuilderFactory dbf = null;
>   +  private static HashMap docBuilderTable = new HashMap ();
>    
>      static {
>        // Create a default instance.
>   @@ -132,12 +133,20 @@
>       */
>      synchronized public static DocumentBuilder getXMLDocBuilder()
>        throws IllegalArgumentException {
>   -    // Step 2: create a DocumentBuilder that satisfies the 
> constraints
>   -    // specified by the DocumentBuilderFactory
>   -    try {
>   -      return dbf.newDocumentBuilder();
>   -    } catch (ParserConfigurationException pce) {
>   -      throw new IllegalArgumentException(pce.toString());
>   +    // 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;
>   +      } catch (ParserConfigurationException pce) {
>   +        throw new IllegalArgumentException(pce.toString());
>   +      }
>        }
>      }
>    }
>   
>   
>   
> 
> --
> To unsubscribe, e-mail:   <mailto:soap-dev-unsubscribe@;xml.apache.org>
> For additional commands, e-mail: <mailto:soap-dev-help@;xml.apache.org>
> 

--
To unsubscribe, e-mail:   <mailto:soap-dev-unsubscribe@;xml.apache.org>
For additional commands, e-mail: <mailto:soap-dev-help@;xml.apache.org>

Reply via email to