gzun...@googlemail.com wrote on 07/19/2011 12:45:49 PM: > I think the relevant complaint is that the DOM isn't thread safe for > read-only operations, which is counter-intuitive unless you have > knowledge of the underlying implementation. I don't think anyone > expects it to be thread safe for updating.
While it may defy your intuition it isn't something that is guaranteed by the spec. If you expect your code to work with an arbitrary DOM implementation you must synchronize access for all operations. > I've tended to use JAXB to transform the XML to java objects, which > I can then make sure are thread safe for read only operations. In general JAXB objects are not guaranteed to be thread-safe either. In particular, DOM is used by default for representing wildcard content (i.e. unknown elements). > On Jul 19, 2011 5:26 PM, <kesh...@us.ibm.com> wrote: > > In 99% of the use cases, locking the individual DOM objects/operations > > would be the wrong level of granularity -- what you really need to prevent > > unexpected results is transaction locking for a group of related changes. > > That really does have to be done at the application level. > > > > Locking every individual operation also can have significant performance > > impact, in these days of multikernel/multiprocessor machines, due to the > > need to flush cache in order to make sure all the processors know the > > lock's state has changed. The days of "synchronize is free" really are > > over. > > > > Also, frankly, I would be reluctant to encourage people to rely on a > > protected DOM since if/when they change platforms their code will break > > unexpectedly. > > > > If you really want locks on every operation, you're free to build a > > "threadsafe DOM manipulation" library which provides threadsafety -- eg > > static Threadsafe.appendChild(Node parent, Node newChild). The code won't > > look exactly like a simple DOM call, but in most JVMs this kind of simple > > "tail call" is pretty efficient, it makes what you're doing explicit, and > > it's portable to any DOM you care to throw at it. > > > > > > ______________________________________ > > "You build world of steel and stone > > I build worlds of words alone > > Skilled tradespeople, long years taught: > > You shape matter; I shape thought." > > (http://www.songworm.com/lyrics/songworm-parody/ShapesofShadow.html) Thanks. Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: mrgla...@ca.ibm.com E-mail: mrgla...@apache.org