On Mon, 20 Aug 2001, Matt Cleveland wrote:

> For performance reasons, I am attempting to
> 1. construct a digester
> 2. configure it with a lot of rules
> 3. parse a document
> 4. parse another document
> 
> I am not trying to utilize a single parser instance from multiple
> threads at the same time.  The most expensive part of parsing our
> documents with the digester is setting up the rules, so I'd like to
> only have to do that once.
> 

Makes sense.

> Unfortunately this does not work because the implementations of
> Rule.finish() in all of the various rules set the rule's member
> variables to null.  For example from ObjectCreateRule:
> 
>     public void finish() throws Exception {
> 
>       attributeName = null;
>       className = null;
> 
>     }
> 
> I realize I can fix this by subclassing each of the rules or
> alternately by subclassing Digester and changing this behavior.  But
> this behavior seems not only inconvenient in my case but meaningless
> in the general case.  The only purpose accomplished by setting the
> members to null is to prevent reuse.  It's not a meaningful cleanup
> step otherwise because the members don't maintain any state except
> that necessary to define the rule.  This doesn't clean up memory in
> Java unless you want the members to be garbage collected but not the
> rule itself, which seems useless because it doesn't allow the Rule
> object to be used to define a different rule since there is no way to
> re-set these members except through the constructor.  So why is the
> code this way?
> 
> I'm hoping someone will either explain or change this behavior.
> 

Sounds like a bug that needs to be fixed.  You *should* be able to re-use
a configured Digester, as long as you don't try it from two threads at the
same time.  I'll go through the Rule implementations today and fix it.

Thanks for catching this!

> Thanks for the help.
> 
> Matt Cleveland
> 

Craig

Reply via email to