DOM classes and thread safety

C

campus

Hi
I've this problem: I've found on
http://xml.apache.org/xerces2-j/faq-dom.html#faq-1
that DOM access is not thread safe!

I've written a class (not static) with a method containing a code like
this:

import org.w3c.dom.*;
import org.apache.xerces.*;
import org.apache.xerces.dom.*;
import org.apache.xerces.parsers.*;
import org.apache.xml.serialize.*;

//create the document object from the string of message
DOMParser parser = new DOMParser();
parser.parse(new InputSource(new StringReader(msg)));
XMLDocument = parser.getDocument();
//set the element root fo the document
rootElement = XMLDocument.getDocumentElement();
....
....
node.getFirstChild().getNodeValue();
.....
....

This class is instantiated inside a jsp and here some methods of this
class are called.
Because the jsp is translated into a servlet and the code written in
the jsp is executed by the servlet
in a thread inside the JVM of the application server, I conclude that
my class is executed in a thread.

I didn't put any "syncronize" anywhere. Have I to worry about that?

Thanks in advance for your answers.
Bye
 
C

campus

Nick Pomfret said:
What problems is it causing you? What are the symptoms?

Now I don't have any problem.
But I fear (if the DOM classes are not thread safe) it could happen
that, for instance, a message treated (by DOMs) by one class could be
maden dirty by another class that at the same time is using the DOM
classes.
I mean if the DOM package inside its project uses some kind of static
attributes, should I syncronize the access to some methods as the
parser.getDocument() or
XMLDocument.getDocumentElement() or others ?
Is it my fear reasonable?

P.S. excuse my rough english
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top