1

我正在使用 oracle 高级队列 (AQ JMS)。我正在尝试使用多个线程来使用 QueueReceiver 来消耗 jms 队列。

问题:该模型分叉了多个线程,但性能仍接近单线程模型。如何增加队列消耗?

以下是代码片段:

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));
        }

消息工作者代码如下所示:

    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.");
        }
    }
4

1 回答 1

0

每个线程应该有一个单独的 JMS 会话。似乎没有为您的代码片段中的每个线程创建一个会话。

于 2013-01-30T20:39:56.297 回答