Forum Stats

  • 3,872,608 Users
  • 2,266,458 Discussions
  • 7,911,263 Comments

Discussions

is JAXP threadsafe

843834
843834 Member Posts: 49,972
edited Jul 26, 2001 10:33AM in Java Technology & XML
Hi,

I am writing a server application in Java which will read a XML file and maintain its DOM structure in memory. This DOM structure will be accessed by multiple threads simultaneously. Some of the threads may modify some nodes. I do not want any thread which is reading a part of the DOM to read partically modified nodes.

Is there any way to lock access to a particular node in a DOM tree. The JAXP documentation does not mention if the methods are synchronized.

Will I have to write a wrapper class around my DOM tree which has synchronized methods ??

Most of the threads will be performing read operation, I do not want the performance of the read operations to suffer because of synchronizing the methods in the wrapper.

Please let me know if you have a solution.

Regards,
Manvendra

Comments

  • 843834
    843834 Member Posts: 49,972
    Hi Mavendra

    As far as I understand it, JAXP is just a wrapper around any specific DOM implementation. That means you have to check the individual DOM implementations (Xerces, Crimson, etc.) for thread safety. I couldn't remeber reading anything about that in the DOM recomendation of the W3C, so I guess it is a bit unlikely that common implementations are thread-safe. I found some postings about this topic on IBMs alphaworks web-site. They basically say that Xerces (or xml4j) can not be considered thread-safe, although these postings were quite old.

    Unless you want to implement your own, thread safe, DOM implementation, I guess you have to write some kind of wrapper that makes sure that methods are only called in a synchronised way.

    Mathias
This discussion has been closed.