Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with DOMParser

843834Nov 17 2005 — edited Nov 17 2005
Hi,

As part of our application, we are creating a static hashmap. Then a DOMParser is created and a XML document is parsed. This DOMParser instance is then 'put' into the static hashmap.

For subsequent requests we get the parser instance from the static hashmap and then access the nodes from the 'document' on the parser. (this is done to conserve the repeated parser creation & document parsing)
private static HashMap parserHash = new HashMap();
DOMParser parser = new DOMParser();
parser.parse(<inSource>);
parserHash.put(<key>, parser);
Then for subsequent access :
DOMParser parser = (DOMParser) parserHash.get(<key>);
Document doc = parser.getDocument();
NodeList nodes = doc.getElementsByTagName(<elementname>);
In the code , we always do get the paser from the hashmap, but sometimes the call to "getElementsByTagName" fails with a "nullpointerexception". This happens sporadically (and we do not remove the nodes from the DOMDocument at any point in the code).

Once the call has failed, it continues to fail for all subsequent calls for that particular node, although it works for other nodes.

I am suspecting that the specific 'node' gets garbage-collected. But since the entire parser object (with its document) is stored into a static hashmap, is it possible that the a specific "Node" gets garbage collected ?

Or is there some kind of threading issue in the DOMParser .

We are using XML4J 4.2.2 on WebSphere 5.1 (this is a multithreaded environment & the problem is observed under high-load conditions only).

Any observations, clues, information on similar experiences appreciated.

Thanks,
Prasad
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2005
Added on Nov 17 2005
2 comments
133 views