简体   繁体   中英

JMS onMessage JBoss, how many threads are used?

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

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.

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