1.

Is Jdom Thread Safe?

Answer»

The core API is intentionally not thread safe. In other words, there are no synchronized blocks within org.jdom. This decision makes sense because we expect the primary JDOM use cases to be:

  • Single thread reads an XML stream into JDOM and looks at it read only.
  • Single thread reads an XML stream into JDOM and modifies it.
  • Single thread reads an XML stream into JDOM and makes it available to a run time system for read only access.

The use case where a "Single thread reads an XML stream into JDOM and exposes it to multiple THREADS to MODIFY its contents" is fairly rare. In that case, JDOM can still be made thread safe but the programmer SIMPLY has to PERFORM their own synchronization, perhaps as synchronizing on the DOCUMENT instance.

On the other hand, there are certain functions that require 'operational' parts of JDOM to be thread safe:

  • org.jdom2.Namespace.getNamespace () is safe
  • All factory-type classes are safe (XPathFactory, etc.)

The core API is intentionally not thread safe. In other words, there are no synchronized blocks within org.jdom. This decision makes sense because we expect the primary JDOM use cases to be:

The use case where a "Single thread reads an XML stream into JDOM and exposes it to multiple threads to modify its contents" is fairly rare. In that case, JDOM can still be made thread safe but the programmer simply has to perform their own synchronization, perhaps as synchronizing on the Document instance.

On the other hand, there are certain functions that require 'operational' parts of JDOM to be thread safe:



Discussion

No Comment Found