Jackson FAQ: Thread-Safety
The basic rule of Jackson thread-safety is that factories follow "thread-safe after configuration" philosophy. This means that:
- Configuring an instance is not synchronized or thread-safe, i.e. do not change settings while using it (which makes sense for other reasons too -- not all settings take effect once mapper has been in use, due to caching of serializers and deserializers)
- Once configuration is complete, operation is fully thread-safe and synchronized in few places where that is needed, for symbol table and buffer reuse.
So as long as you first configure such factories from a single thread, and only then use it (from any number of threads), usage will be thread-safe without additional synchronization.
This rule specifically is used for:
ObjectMapper (and sub-classes)
JsonFactory (and sub-classes, like SmileFactory)
Note that more recently some new factory-like classes use "Fluent" pattern, whereby instances are immutable (and thus fully thread-safe!), and differently configured instances are constructed by factory methods. Specifically:
ObjectReader and ObjectWriter instances are immutable and thread-safe: they are created by ObjectMapper, and once constructed, their state NEVER CHANGES. To get instance with different configuration, one uses factory methods to create NEW INSTANCES (existing one is not changed). This allows complete thread-safe use at any point in life cycle.
This latter approach is preferred for future development, so new factory types will probably follow same style.
