gpt4 book ai didi

java - 当我关闭 Tomcat 时,spring-rabbit 不会停止它启动的线程

转载 作者:行者123 更新时间:2023-11-28 23:33:04 25 4
gpt4 key购买 nike

当我关闭 tomcat 时,我在日志中收到这些消息并且 JVM 没有释放该进程:

Jan 16, 2015 4:20:25 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myproject] appears to have started a thread named [SimpleAsyncTaskExecutor-1] but has failed to stop it. This is very likely to create a memory leak.
Jan 16, 2015 4:20:25 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myproject] appears to have started a thread named [pool-1-thread-1] but has failed to stop it. This is very likely to create a memory leak.
Jan 16, 2015 4:20:25 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myproject] appears to have started a thread named [pool-1-thread-2] but has failed to stop it. This is very likely to create a memory leak.
Jan 16, 2015 4:20:25 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myproject] appears to have started a thread named [pool-1-thread-3] but has failed to stop it. This is very likely to create a memory leak.
Jan 16, 2015 4:20:25 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myproject] appears to have started a thread named [SimpleAsyncTaskExecutor-1] but has failed to stop it. This is very likely to create a memory leak.
Jan 16, 2015 4:20:25 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myproject] appears to have started a thread named [pool-1-thread-4] but has failed to stop it. This is very likely to create a memory leak.

我使用调试器查看这些线程在关闭前在做什么,这是它们的线程转储之一:

"SimpleAsyncTaskExecutor-1@4510" prio=5 tid=0x29 nid=NA waiting
java.lang.Thread.State: WAITING
at sun.misc.Unsafe.park(Unsafe.java:-1)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2082)
at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:302)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:945)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:934)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$600(SimpleMessageListenerContainer.java:78)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1045)
at java.lang.Thread.run(Thread.java:745)

我用这个作为 spring/spring-rabbit 对这个问题负责的证据。

这是我的 Spring 上下文中与 rabbit mq 有关的部分:

<rabbit:connection-factory id="connectionFactory" host="host" port="5672" username="username" password="password" virtual-host="/projectname"/>

<rabbit:admin connection-factory="connectionFactory"/>
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" exchange="barExchange"/>

<rabbit:queue name="barQueueCleanDev" />
<rabbit:queue name="barQueueFooDev" />

<rabbit:topic-exchange name="barExchange" >
<rabbit:bindings>
<rabbit:binding queue="barQueueFooDev" pattern="bar.queue.foo.dev" />
<rabbit:binding queue="barQueueCleanDev" pattern="bar.queue.clean.dev" />
</rabbit:bindings>
</rabbit:topic-exchange>

<rabbit:listener-container connection-factory="connectionFactory" acknowledge="auto" concurrency="1" max-concurrency="1" requeue-rejected="false" error-handler="barServiceErrorHandler">
<rabbit:listener ref="barService" method="create" queue-names="barQueueCleanDev"/>
<rabbit:listener ref="barService" method="createFromFoo" queue-names="barQueueFooDev"/>
</rabbit:listener-container>

我如何告诉 spring-rabbit 在我关闭 tomcat 时停止它创建的线程?

我正在使用 spring-rabbit 版本 1.4.2.RELEASE

最佳答案

我通过在 servlet 的 destroy 方法中手动调用我的 Spring 的 applicationContext.destroy() 来解决这个问题。

关于java - 当我关闭 Tomcat 时,spring-rabbit 不会停止它启动的线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27994902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com