Herry wrote:
> so if I do require thread safety for my application,
> what are the possible solutions (at least as far as
> xerces is concern). Will traversing the entire tree
> during the initialisation stage solve the problem?

You can synchronize on the document but then this would
then "lock" the entire tree no matter where it's being
accessed by the various threads. So finer grained locking
would be preferred.

Here's a simple solution for better synchronization
access of the document: always synchronize on the *node* 
that you're making the call on. 

When you parse an XML file and are returned the document, 
you cannot be guaranteed that all of the sub-nodes (or 
data) has been properly instantiated and linked together. 
But if all of your code that tries to access the Document 
methods (children, etc) is synchronized on the Document 
object, then there won't be any problem. For example:

  Document doc = /* ... */

  Element root = null;
  synchronized (doc) {
    root = doc.getDocumentElement();
  }

Accessing other nodes in the document would be done the
same way:

  Node child = null;
  synchronized (root) {
    child = root.getFirstChild();
  }

How much you synchronize -- whether it's whole blocks of
code or just the access of each node is up to you. It's
more work on your part but it's the only way to make
sure that you don't have problems accessing the document
from multiple threads.

-- 
Andy Clark * [EMAIL PROTECTED]

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

Reply via email to