You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Hans Bjurström <ha...@pipebeach.com> on 2001/01/15 14:01:50 UTC

DOM model and thread safeness

Hello, 

how should I handle multiple threads accessing a common DOM tree and 
accessing it concurrently? I don't do any updates, e.g the DOM data
model is constant
after having been built initially.

However, I get null pointer exceptions executing getChildNodes on Node
objects
using xerces-1.2.2(java) at
org.apache.xerces.dom.ChildAndParentNode.item(ChildAndParentNode.java:78
7)

Must I externally synchronize the accesses anyway?

Hans Bjurström

Re: DOM model and thread safeness

Posted by Andy Clark <an...@apache.org>.
Hans Bjurström wrote:
> However, I get null pointer exceptions executing getChildNodes on Node
> objects
> using xerces-1.2.2(java) at
> org.apache.xerces.dom.ChildAndParentNode.item(ChildAndParentNode.java:78
> 7)
> 
> Must I externally synchronize the accesses anyway?

Turn off the deferred DOM implementation so that the nodes are
created at parse time. Check the features list in the docs for
the information.

This should solve most of the threading issues. Arnaud: is
there any lurking lazy-eval code in the non-deferred case?
Of course, the safest thing is always to synchronize your
access to the document.

-- 
Andy Clark * IBM, TRL - Japan * andyc@apache.org

RE: DOM model and thread safeness

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
I'm still looking for a little bit of clarity on the definition that is
being used for "thread-safe".  I do understand in the traditional sense what
this means, but I am trying to determine if there are any issues with
instantiating multiple instances of the Xerces SAX parser and running them
simultaneously.  I have no problem adding appropriate synchronization in my
application where needed -- that is no big deal...what I am getting at is
are there static variables, blocks, etc. that might compromise the state of
the parser if multiple instances are created and run simultaneously.

Does anyone have any insight on this?

Brad

-----Original Message-----
From: Andy Clark [mailto:andyc@apache.org]
Sent: Thursday, January 18, 2001 12:12 AM
To: xerces-j-dev@xml.apache.org
Subject: Re: DOM model and thread safeness


David Corbin wrote:
> I was told just last week that Xerces 1.2.3 (and older) is not thread
> safe, but that the latest CVS source code is.  However, I have been
> having a multithreaded problem with that code, but only with IBM's 1.3
> JDK.

No version of the Xerces DOM has been thread-safe. It's too much
of a performance hit for people only accessing the document with
one thread at a time. You'll have to add thread-safety in your
application.

--
Andy Clark * IBM, TRL - Japan * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: DOM model and thread safeness

Posted by Andy Clark <an...@apache.org>.
David Corbin wrote:
> I was told just last week that Xerces 1.2.3 (and older) is not thread
> safe, but that the latest CVS source code is.  However, I have been
> having a multithreaded problem with that code, but only with IBM's 1.3
> JDK.

No version of the Xerces DOM has been thread-safe. It's too much
of a performance hit for people only accessing the document with
one thread at a time. You'll have to add thread-safety in your
application.

-- 
Andy Clark * IBM, TRL - Japan * andyc@apache.org

RE: DOM model and thread safeness

Posted by Brad O'Hearne <ca...@megapathdsl.net>.
I also have a question about "thread safeness", and that is how exactly this
term is being defined.  I am not accessing the same parser or tree instances
with multiple threads, (in fact I am using SAX), but I am running multiple
instances of a SAXParser simultaneously in different threads.  While we
might think we can assume this is fine, there are some small holes in the
Java language (which may be fixed by now) which scenarios like this can
cause problems, because the separate threads and instances actually end up
trying to access global resources (which happens down in the JDK code).

Can anyone comment as to whether there could possibly be problems with doing
this?

Brad

-----Original Message-----
From: dcorbin [mailto:dcorbin]On Behalf Of David Corbin
Sent: Monday, January 15, 2001 6:17 AM
To: xerces-j-dev@xml.apache.org
Subject: Re: DOM model and thread safeness


I was told just last week that Xerces 1.2.3 (and older) is not thread
safe, but that the latest CVS source code is.  However, I have been
having a multithreaded problem with that code, but only with IBM's 1.3
JDK.


Hans Bjurström wrote:
>
> Hello,
>
> how should I handle multiple threads accessing a common DOM tree and
> accessing it concurrently? I don't do any updates, e.g the DOM data
> model is constant
> after having been built initially.
>
> However, I get null pointer exceptions executing getChildNodes on Node
> objects
> using xerces-1.2.2(java) at
> org.apache.xerces.dom.ChildAndParentNode.item(ChildAndParentNode.java:78
> 7)
>
> Must I externally synchronize the accesses anyway?
>
> Hans Bjurström
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

--
David Corbin
Mach Turtle Technologies, Inc.
http://www.machturtle.com
dcorbin@machturtle.com

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: DOM model and thread safeness

Posted by David Corbin <dc...@machturtle.com>.
I was told just last week that Xerces 1.2.3 (and older) is not thread
safe, but that the latest CVS source code is.  However, I have been
having a multithreaded problem with that code, but only with IBM's 1.3
JDK.


Hans Bjurström wrote:
> 
> Hello,
> 
> how should I handle multiple threads accessing a common DOM tree and
> accessing it concurrently? I don't do any updates, e.g the DOM data
> model is constant
> after having been built initially.
> 
> However, I get null pointer exceptions executing getChildNodes on Node
> objects
> using xerces-1.2.2(java) at
> org.apache.xerces.dom.ChildAndParentNode.item(ChildAndParentNode.java:78
> 7)
> 
> Must I externally synchronize the accesses anyway?
> 
> Hans Bjurström
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

-- 
David Corbin 		
Mach Turtle Technologies, Inc.
http://www.machturtle.com
dcorbin@machturtle.com