简体   繁体   中英

Thread safety with Spring boot application

Hi I was wondering about thread safety in spring boot applications.

I have configured JMS listener that reads messages concurrently and then I call a mapper to convert the request into a desirable format and then send message.

So, Coming to mapper now that I am listening messages concurrently do I need to ensure thread safety in my code?

Application servers use several concepts to make multithreading easy for the average programmer.

The most important concept is thead confinement. To understand the concept, read the answers to this question .

In your situation, there is more than one thread involved, but there is also some API that enables you to handle data from one thread to the other in a safe way. Most of the time there are thread pools envolved, see Introduction to Thread Pools in Java .

In JMS there are some objects that are not allowed to be used in different threads (eg the Session object), some are (eg the Connection, the JmsTemplate). Read the answers to "Why JMS Session Object is not thread safe?" . The consequences are listed here .

I recommend reading the Spring documentation on this topic .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM