问题
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