2

I have a JMS Listener, inside the listener I'm using an ExecutorService to run a worker on a fixed number of threads. like so:

public void onMessage(Message m) {
    executor.execute(new Worker(m));
}

This executor has 10 threads, if I get 100 messages in at the same time and it takes a few seconds for each of these workers to run, am I going to have 90 JBoss JMS threads waiting on the 10 active Worker? So do each of these incoming messages get their own thread and eat up my resources while waiting?

Am I doing it completely wrong, is there a better way?

I'm using JBoss EAP and HornetQ

Rocky Pulley
  • 22,531
  • 20
  • 68
  • 106

1 Answers1

2

You don't need Executor, each MDB runs in its own thread. And you can control minimal and maximal number of sessions that can deliver messages to this MDB. Please see How to limit the number of MDB instances listening to a Jboss JMS queue. So in your scenario, you can define MDB like this:

@MessageDriven(activationConfig = {   
@ActivationConfigProperty( propertyName = "destinationType", propertyValue = "javax.jms.Queue" ),   
@ActivationConfigProperty( propertyName = "destination", propertyValue = "queue/myQueue"),
@ActivationConfigProperty( propertyName = "maxSession", propertyValue = "20")  
})
public class MyBean implements MessageListener {
  public void onMessage(Message m) {
    // do something with message
  }
}

If 100 messages are waiting in a queue, first 20 messages are processed and the rest of messages are waiting in a queue. As one message is processed (and removed from queue), next message is processed.

Community
  • 1
  • 1
Magic Wand
  • 1,572
  • 10
  • 9