Java receiver with multiple jms threads

I am using oracle Advanced Queuing (AQ JMS). I am trying to use multiple threads to use jms queue using QueueReceiver.

Question This plug model has multiple threads, but performance is still close to a single-threaded model. How to increase the consumption of the queue?

Below is the snipet code:

final QueueReceiver queueReceiver = getQueueReceiver(queueSession); qConn.start(); //THREAD POOL SIZE final int threadPoolSize = getThreadCount(); final ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize); for (int i = 0; i < threadPoolSize; i++) { executor.submit(new MessageWorker(queueReceiver)); } 

And the working message code is as follows:

  class MessageWorker extends Thread { MessageConsumer messageConsumer; public MessageWorker(MessageConsumer subs) { this.messageConsumer = subs; } /** * @see java.lang.Thread#run() */ @Override public void run() { try { while (true) { try { Message msg = messageConsumer.receive(); if (null != msg) { //log message logMessage(msg); //handle message handleMessage(msg); //ack msg.acknowledge(); } } catch (JMSException e) { log.error(e); } } } catch (Exception e) { log.error(e); } finally { log.info("Thread:" + this.getName() + " terminated."); } } 
+1
java multithreading jms
source share
1 answer

Each thread must have a separate JMS session. There does not seem to be a session created for each thread in the code snippet.

0
source share

All Articles