简体   繁体   中英

javax.jms.MessageListener: What additional threading concerns to take care of?

In this nice article on JMS, Bruce Snyder (Author of "ActiveMQ in Action") mentions:

[one] of the options for implementing a message listener to be used with the Spring DMLC is using javax.jms.MessageListener - It is a standardized interface from the JMS spec but handling threading is up to you .

He doesnt talk about threading in the other two options: Spring SessionAwareMessageListener and MessageListenerAdapter.

My question is: What additional threading concerns are to be addressed with the use of the plain javax.jms.MessageListener, compared to the other two approaches ?

I am thinking that regardless of what option I choose from the above 3, if my listener will be receiving messages on multiple threads, my listener implementation has to be thread-safe.

I went through the examples Bruce had created in github for all the three options. I didnt see any specific handling for threads in any case. The xmls of simple and session-aware consumers are almost the same.

As long as your not keeping any state in your MessageListener implementations(through say an instance variable), you don't have to worry about thread-safety with any of the three approaches. If you are keeping state, then like in any multi-threading scenario, you will have to take care of how you synchronize access to the state.

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