From: "David Hooker" <[EMAIL PROTECTED]>
> How do you cache the parser?

Just like the example I coded below. i.e. by reusing the same SAXReader
instance in the same thread. Creating a new instance each time results in a
new underlying SAX parser, the XMLReader, being created which tends to
reinitialize the underlying parser each time.

Another approach to using ThreadLocal could be to use an object pool
implementation.

> e.g. if using the dom4j SAXReader, it can often be useful to use
> ThreadLocal
> to pool them by thread. e.g.
>
> ThreadLocal pool= new ThreadLocal() {
>     protected Object initialValue() {
>         return new SAXReader();
>     }
> };
>
> ...
> SAXReader reader = (SAXReader) pool.get();
> reader.parse( "foo.xml" );


James
-------
http://radio.weblogs.com/0112098/


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


-------------------------------------------------------
This sf.net email is sponsored by: Jabber - The world's fastest growing 
real-time communications platform! Don't just IM. Build it in! 
http://www.jabber.com/osdn/xim
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to