The non-deferred DOM (yes it's still supported; it's the default impl for 
an LSParser) isn't thread-safe for reads either. For instance, it caches 
the last position accessed in a NodeList (returned from 
Node.getChildNodes()) as well as its length. This is done for performance 
reasons. Without it we would need to walk through the N-1 siblings to get 
the Nth item in the list and would have to walk across all of the siblings 
to get the length of the list. Due to the way the caching mechanism works, 
concurrent reads of a NodeList can lead to the NPEs which Soumya is 
getting or incorrect values being returned from item() or getLength().

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

[EMAIL PROTECTED] wrote on 07/24/2007 02:54:01 PM:

> Per the W3C spec, the DOM API does not promise to support 
> multithread access. Doing so would impose performance/implementation
> limitations on all applications, even single-threaded ones, which 
> was considered undesirable. Also, in most cases what you really need
> is threadsafety at a much higher level than single DOM operations.
> 
> In *some* (but not all) DOMs, you can get away with concurrent reads
> as long as nobody is altering the DOM. The Xerces "delayed DOM" is 
> one which does _not_ promise to support that; if you tell Xerces to 
> use the fully-preconstructed DOM implementation instead (do we still
> support it?) that may get you back on the air... but this is an 
> implementation-specific hack and is not really good coding practice.
> It's better to put explicit thread handshaking into your application
> code where needed, via the use of appropriate semaphores and locks.
> 
> ______________________________________
> "... Three things see no end: A loop with exit code done wrong,
> A semaphore untested, And the change that comes along. ..."
> -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (http://www.ovff.
> org/pegasus/songs/threes-rev-11.html)

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to