ActiveMQ Transport Thread is not terminated when main ends

早过忘川 提交于 2020-02-22 07:39:06

问题


This is how I start connection:

factory = new PooledConnectionFactory(brokerURL);

brokerURL is "failover:(tcp://host1.com:61616,tcp://host2.com:61616)?randomize=false&jms.useAsyncSend=false&jms.dispatchAsync=false&maxReconnectAttempts=30&maxReconnectDelay=3000"

Connection is started:

connection = factory.createConnection("", ""); 
connection.start();

Application performs its usual tasks before connections gets closed:

connection.close();

main method is finished, but JVM is not, because there are still a few ActiveMQ threads active:

Thread [ActiveMQ Transport: tcp://host1.com/ip_address:61616@2455] (Running)    
Daemon Thread [ActiveMQ InactivityMonitor ReadCheckTimer] (Running) 
Daemon Thread [ActiveMQ InactivityMonitor WriteCheckTimer] (Running)    
Daemon Thread [ActiveMQ InactivityMonitor Worker] (Running) 

How am I supposed to close it so that the threads above will shutdown too. ActiveMQ version 5.10.0

thanks in advance


回答1:


Fixed with (PooledConnectionFactory) factory).stop();




回答2:


Or add "daemon=true" as a connection url parameter.

As per http://activemq.apache.org/tcp-transport-reference.html

If true the transport thread will run in daemon mode

The main JVM thread will exit even if daemon threads are running.



来源:https://stackoverflow.com/questions/29695079/activemq-transport-thread-is-not-terminated-when-main-ends

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!