The moose likes Performance and the fly likes XML Parsers to use object pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Performance
Reply Bookmark "XML Parsers to use object pooling" Watch "XML Parsers to use object pooling" New topic
Author

XML Parsers to use object pooling

Jes Sie
Ranch Hand

Joined: Jul 24, 2001
Posts: 188
Dear people,
I'm a newbie in this forum.
Somebody suggested that the XML parser used in our project should be 'object pooled'. I understand object pooling. In fact, I've used commons-pooling by Jakarta before. But, I don't quite understand how a parser instantiation would cause memmory consumption/performance issue. Wouldn't it best be in some kinda Singleton?
Any hints would be appreciated. Thanks.


Thank you.<br /> <br />- Jess Sie<br /> <a href="mailto:jess@see-consulting.com" rel="nofollow">jess@see-consulting.com</a>
Jes Sie
Ranch Hand

Joined: Jul 24, 2001
Posts: 188
Hellou, anyone out there please comment....
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18652
The problem with a singleton here is if you ever have more than one thread trying to use the parser. A single parser really can't be used this way - so you'd need either a new parser for each thread, or an object pool. (Or you can use synchronization to ensure that only one thread uses the parser at a time - but that's slower.) If you're doing a lot of parsing, and/or if the parsers are fairly large, complex objects (which they often are) then the object pool may be best in the long run. As usual though, it's best if you perform some profiling first to see if parser instantiation and GC is really a big contributor to current memory/performance problems (if there are any). If it ain't broke, don't fix it.
[ December 05, 2002: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
 
 
subject: XML Parsers to use object pooling
 
Threads others viewed
Java Object to XML using Xerces
Parser Pooling with JDOM
ThreadLocal & Servlet - Store XML parser for reuse?
New to XML, need help on start
Which one is the best XML parser?
IntelliJ Java IDE