日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java多线程activemq,多线程JMS客户端ActiveMQ

發布時間:2025/3/8 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java多线程activemq,多线程JMS客户端ActiveMQ 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在使用以下代碼創建多個JMS會話,以供多個使用者使用消息。我的問題是代碼以單線程方式運行。即使消息存在于隊列中,第二個線程也無法接收任何內容,而是繼續輪詢。同時,第一個線程完成對第一批的處理,然后返回并使用剩余的消息。這里的用法有什么問題嗎?

static {

try {

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://172.16.143.99:61616");

connection = connectionFactory.createConnection();

connection.start();

} catch (JMSException e) {

LOGGER.error("Unable to initialise JMS Queue.", e);

}

}

public JMSClientReader(boolean isQueue, String name) throws QueueException {

init(isQueue,name);

}

@Override

public void init(boolean isQueue, String name) throws QueueException

{

// Create a Connection

try {

// Create a Session

session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

if (isQueue) {

destination = new ActiveMQQueue(name);// session.createQueue("queue");

} else {

destination = new ActiveMQTopic(name);// session.createTopic("topic");

}

consumer = session.createConsumer(destination);

} catch (JMSException e) {

LOGGER.error("Unable to initialise JMS Queue.", e);

throw new QueueException(e);

}

}

public String readQueue() throws QueueException {

// connection.setExceptionListener(this);

// Wait for a message

String text = null;

Message message;

try {

message = consumer.receive(1000);

if(message==null)

return "done";

if (message instanceof TextMessage) {

TextMessage textMessage = (TextMessage) message;

text = textMessage.getText();

LOGGER.info("Received: " + text);

} else {

throw new JMSException("Invalid message found");

}

} catch (JMSException e) {

LOGGER.error("Unable to read message from Queue", e);

throw new QueueException(e);

}

LOGGER.info("Message read is " + text);

return text;

}

總結

以上是生活随笔為你收集整理的java多线程activemq,多线程JMS客户端ActiveMQ的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。