1

I need to write a multithreaded JMS producer, and a multithreaded JMS consumer; I am relatively new to working with JMS and I have never had to multithread before. I see in the API that you can send and receive messages asynchronously using a Completion Listener for the producer and a Message Listener for the consumer. Does this mean that using a completion listener and a message listener causes the program to be multithreaded? If not how do you go about writing a multithreaded producer and a multithreaded consumer?

tc03
  • 11
  • 1
  • 2
  • 1
    Asynchrony and multithreading are 2 different things, they both can achieve concurrency. And I think concurrency is what you looking for – Sleiman Jneidi Jun 07 '15 at 22:39
  • Good discussion about multiple threads for JMS http://stackoverflow.com/questions/25832159/single-vs-multi-threaded-jms-producer Another JMS Design document from Oracle http://docs.oracle.com/cd/E11035_01/wls100/jms/design_best_practices.html – bobs_007 Jun 07 '15 at 23:08
  • Are you writing a Java EE application, right? In Java EE working with your application server settings you can set a number of instances for the Message Driven Bean that is going to consume messages incoming in a JMS queue, so you will not need to manually handle threads in your code for the consumer part: the application server will take care on its own, you will only need to write thread-safe code on the MDB onMessage method's body. For the producer part I think you will need to handle threads on your own... – alessiop86 Jun 07 '15 at 23:14

1 Answers1

1

Avoid Multi-threading The JMS Specification states that multi-threading a session, producer, consumer, or message method results in undefined behavior except when calling close(). For this release, if WebLogic JMS determines that you created a multi-threaded producer, the server instance throws a JMSException. If your application is thread limited, try increasing the number of producers and sessions.

Karthik M
  • 89
  • 5