我使用Spring JMS和以下上下文XML文件。DefaultMessageListenerContainer不會停止
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
p:brokerURL="tcp://localhost:61616" />
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop"
p:connectionFactory-ref="connectionFactory" />
<bean id="queue1" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="foo.bar"/>
</bean>
<bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer" destroy-method="destroy"
p:autoStartup="true"
p:connectionFactory-ref="pooledConnectionFactory"
p:destination-ref="queue1"
p:messageListener-ref="listener"
p:acceptMessagesWhileStopping="false"
p:sessionTransacted="true" />
我的應用程序的命令行獨立的,而且,看起來是這樣的:
public static void main(String[] args) throws JMSException, InterruptedException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("my-context.xml");
context.registerShutdownHook();
App app = context.getBean("app", App.class);
app.start();
}
這裏的問題是,當主線程結束,進程不會停止。我目前猜測聽衆容器沒有停止。
這是在最後的日誌消息:
16:54:02,747 DEBUG [main] DefaultListableBeanFactory:246 - Returning cached instance of singleton bean 'app'
16:54:02,747 INFO [main] App:47 - Terminating...
16:54:02,747 INFO [main] App:51 - Terminated.
16:54:02,771 DEBUG [listenerContainer-1] TaskRunnerFactory:91 - Initialized TaskRunnerFactory[ActiveMQ Session Task] using ExecutorService: [email protected]
16:54:03,783 DEBUG [listenerContainer-1] ActiveMQSession:559 - ID:Daniels-MacBook-Pro.local-56179-1359680042616-1:1:1 Transaction Commit :null
16:54:04,784 DEBUG [listenerContainer-1] ActiveMQSession:559 - ID:Daniels-MacBook-Pro.local-56179-1359680042616-1:1:1 Transaction Commit :null
16:54:05,785 DEBUG [listenerContainer-1] ActiveMQSession:559 - ID:Daniels-MacBook-Pro.local-56179-1359680042616-1:1:1 Transaction Commit :null
16:54:06,787 DEBUG [listenerContainer-1] ActiveMQSession:559 - ID:Daniels-MacBook-Pro.local-56179-1359680042616-1:1:1 Transaction Commit :null
16:54:07,788 DEBUG [listenerContainer-1] ActiveMQSession:559 - ID:Daniels-MacBook-Pro.local-56179-1359680042616-1:1:1 Transaction Commit :null
...
僅供參考,我試圖關閉自動啓動(通過設置p:autoStartup="false"
)和手動啓動/停止代碼中的容器,但是,它沒」不管工作。
不,它沒有工作。另外,我已經調用了'context.registerShutdownHook()'。 –