Skip to content
Advertisement

Is the Jackson2JsonMessageConverter class thread-safe?

I’m using this class and I’m wondering whether it’s thread safe:

https://docs.spring.io/spring-amqp/api/org/springframework/amqp/support/converter/Jackson2JsonMessageConverter.html

The docs don’t make any claims about this. I skipped through the code and found no signs it’s not thread-safe. It’s using an ObjectMapper internally, which is thread-safe according to docs:

https://fasterxml.github.io/jackson-databind/javadoc/2.13/com/fasterxml/jackson/databind/ObjectMapper.html

Mapper instances are fully thread-safe provided that ALL configuration of the instance occurs before ANY read or write calls.

So I would assume that Jackson2JsonMessageConverter is thread-safe, as long as I don’t change any configuration before doing any operation.

Advertisement

Answer

If you don’t change any properties of the Jackson2JsonMessageConverter at runtime, then it is indeed thread-safe. It is always unpredictable for the next message to convert if new value for properties are going to have effect not. In general most of components in the framework are thread-safe since they are stateless as long as you don’t change the component configuration at runtime.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement