Multithreaded Applications

The generated Libraries are thread safe with a small caveat.

Note: By thread safe we mean that 2 instances of the same object can be used in different threads safely. If you want to share the same object from 2 different threads, then you must control the synchronization yourself.

The settings that effect serialization (both to and from XML) are held in a class called XmlSerialzationContext. Each of the toXmlXXXX & fromXmlXXXX methods accept an instance of the XmlSerialzationContext object. For convenience there are a number of simple over loads (of the toXmlXXXX and fromXmlXXX methods) that make use of a globally defined instance of a XmlSerialzationContext object.

This globally defined instance may be a problem if you are running in a multithreaded environment. Typically the object is setup at the start of the app and never changed. The object is thread safe for reading, but not writing. So if you are planning to change this object during the lifetime of the app, then it is recommended that you create an instance for each thread and use this instance explicitly when calling toXml and fromXml methods.

Note : This global instance was created to make things simple for the majority of people (who never concern themselves with the complexities of threading).


See also: XML Databinding Help

Add Feedback