I forgot to mention this point. We in fact are running in multi-threaded mode and I am creating a pool of TranformerFactories and transformers. Each thread needs to go through a synchronized call to get access to them. As you pointed out, TransformerFactory is not thread-safe and I found it the hard way (got a lot of NullPointerExceptions when I was not using the pool).
Thanks !! -----Original Message----- From: Andreas Delmelle [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 05, 2008 5:07 PM To: [email protected] Subject: Re: Fop 0.20.5 vs Fop Trunk Performace On Mar 5, 2008, at 21:36, Andreas Delmelle wrote: > On Mar 5, 2008, at 21:09, Puppala, Kumar (LNG-CON) wrote: >> >> // Setup JAXP using identity transformer >> TransformerFactory factory = >> TransformerFactory.newInstance(); >> Transformer transformer = factory.newTransformer(); // >> identity transformer > > Interesting! So the memory leaks are not inherent to FOP it would > seem, but to the way the JAXP-pattern is used. > >> >> When you use the TransformerFactory in this manner (within each >> run), the SAXParser instance created by the transformer is held in >> memory. On subsequent runs, I noticed more and more instances of >> SAXParser's in memory. To fix this, I moved this code to the >> calling function, thus keeping a single copy of transformer. > > Makes sense. The TransformerFactory should indeed (better practice) > be declared only once. If you ever plan on using XSLT stylesheets, > you could also cache a Templates object. This made me re-read the API docs, and it this may suit your particular setup, I was wrong and in general one should actually be *very* careful when re-using either the TransformerFactory or the Transformer. Neither of the objects are thread-safe, so this can only be done if you are absolutely certain that no two threads will concurrently access either of them... Re-using them in sequence is no problem whatsoever, and actually seems to be recommended, based on your observations. Cheers Andreas --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
