[jdom-interest] Thread questions regarding JDOM SAXBuiler?
David Wall
d.wall at computer.org
Tue Aug 31 09:13:55 PDT 2004
> Yes, documents are discarded after being built. There are many variations
> you can do in a test like this. My guess is that it's String/StringBuffer
> handling in SAXBuilder and/or Xerces that accounts for the resuts.
This is odd. Even the SAXBuilder javadocs show that it makes sense to NOT
reuse the parser if doing a large number of files in sequence:
/**
* Specifies whether this builder shall reuse the same SAX parser
* when performing subsequent parses or allocate a new parser for
* each parse. The default value of this setting is
* <code>true</code> (parser reuse). Setting the value to
* <code>false</code> can result in a performance improvement when
parsing
* large numbers of files in sequence.
* <p>
* <strong>Note</strong>: As SAX parser instances are not thread safe,
* the parser reuse feature should not be used with SAXBuilder instances
* shared among threads.</p>
*
* @param reuseParser Whether to reuse the SAX parser.
*/
But why is that? Why would reusing a parser cause a performance decline?
The SAXBuilder code is so thin that it seems counterintuitive. By reusing
the parser, we save the calls to createParser() and installing any optional
filters. Why does that result in less performance? Is this a bug/issue
with the underlying Xerces parser?
The construction of the SAXBuilder object is extremely small, so it also
doesn't seem to make sense to pool them. The cost of instantiating the
SAXBuilder object appears to be quite small, and if reusing the parser has
not benefit, it seems good enough to simply create the SAXBuilder, build()
and then discard it.
Can that really be the case? It sure would make life easier, even if it
seems a bit odd to me...
Thanks,
David
More information about the jdom-interest
mailing list