Announcement Announcement Module
Collapse
No announcement yet.
Confusion on concurrency in Listener template Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Confusion on concurrency in Listener template

    Hi,

    I have few confusion. I will really appreciate if someone correct me.

    A)
    In Spring messaging, we have 2 things

    1) JMS Listener Container
    2) Message Driven POJP (MDP) - Which is a consumer (like EJB MDB)


    Now, in Listener Container we have a "concurrency" attribute. By "concurrency" what I understand is that the number of MDP instance to be created for a single Listener container. Please let me know whether my understanding is correct or not.

    As I understand everything in Spring by default is Singleton bean but if we mention the "concurrency" value more than 1, MDP will no longer be singleton. Please correct my understanding.


    B) Please let me know if there could be any thread related issue in MDP.

    C) I am also confused about the behavior of "prefetch" attribute

    Thanks a lot.

    Best Regards,

    ssroy

  • #2
    In both occasions you are wrong...

    The ListenerContainer will remain a singleton no matter how much you specify on concurrency, the same goes for your MDP. Concurrency is simply configuring how many work threads are assigned the task of retrieving messages (and how many connections/sessions are created), default is 1.

    I suggest the JMS chapter of the reference guide as well as the javadoc of the classes and also I suggest to take a look at the implementation of those classes.

    Comment


    • #3
      Thanks a lot Marten for prompt reply.

      I got your point. But if we create multiple threads to consume messages from provider but have only one instance of MDP (since singleton) then how MDP is going to process these messages. Will these messages be queued or there could be thread safety issues as well? I am really sorry if I am missing something.

      Thanks again. I have read the reference doc but I will go through it again.

      Best Regards,

      ssroy

      Comment


      • #4
        If your MDP is stateless there isn't an issue, if it isn't stateless it shouldn't be a singleton to start with.

        Comment


        • #5
          Thanks for the inputs.

          Our MDP is implementing MessageListener interface and Stateless in nature.

          But the point that I had mentioned i.e., will the message be queued to be consumed by MDP" is not clear.

          Also, can you please tell me/refer to any article for how to create Stateful consumer.

          Thanks for all your valuable inputs.

          Best Regards - ssroy

          Comment


          • #6
            They will simply be handled by a available thread, I suggest reading 'java concurrency in practice' it is a good read and explains concurrency.

            Comment


            • #7
              Thanks a lot Marten. Really appreciate to take out your time for clearing the doubt.

              Best Regards - ssroy

              Comment

              Working...
              X