I have been using a pool of SAX parsers for quite some time to handle lots
of small XML documents
we receive over the web. It works pretty well. As you noted the only
requirement on reuse is that the
parser not be used by more than one thread at a time.

I created a PooledSAXReader that extends org.dom4j.io.SAXReader. The
constructor saves a
reference to the pool it belongs to. A close() method returns the SAXReader
to its pool. Servlets
checkout a SAXReader from a pool, use it to parse a document and return it
to the pool by calling
close() on the SAXReader.

Chuck Simpson
[EMAIL PROTECTED]


|---------+-------------------------------------->
|         |           "K.Gillies"                |
|         |           <[EMAIL PROTECTED]>      |
|         |           Sent by:                   |
|         |           [EMAIL PROTECTED]|
|         |           ceforge.net                |
|         |                                      |
|         |                                      |
|         |           05/03/02 05:48 PM          |
|         |                                      |
|---------+-------------------------------------->
  
>----------------------------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                                              |
  |        To:      [EMAIL PROTECTED]                                   
                                              |
  |        cc:                                                                         
                                              |
  |        Subject: [dom4j-user] Reuse of SAXReader?                                   
                                              |
  
>----------------------------------------------------------------------------------------------------------------------------------|




Hi,
   Since I need to parse a lot of documents of a few different types
(instances I guess), I'd like to create one or more XML parsers (as
SAXReader instances) to reuse.  I'd like to treat these parsers as
resources like database connections, for instance.

   So my question is, is it ok to reuse a SAXReader or do I need to
create a new one each time I need to parse a document.  I know that the
XML parser is not reentrant.  I've looked at the source for SAXReader,
and I see that quite a bit is done when read is called but a new
instance of the parser is not created if it already exists
(getXMLReader) so this suggests to me that someone expected reuse of
SAXReader.  Please comment on the use of SAXReaders as pooled objects.
If you think this is a total waste of time, I'd be interested in hearing
that too.  I've not done any benchmarking that suggests that this is
really where I'm spending a lot of time, but I do think parsers are
pretty heavyweight objects to create every time I parse a document.

   The following is from a newcomer to dom4j so take that into
consideration too!  If you don't mind, please cc your email to
[EMAIL PROTECTED], I'm not (yet) a list member.  I'm just testing dom4j.

Thanks,
K.Gillies


_______________________________________________________________

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user






_______________________________________________________________

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to