gpt4 book ai didi

tomcat - Spring rabbit启动不让Tomcat关闭的SimpleAsyncTaskExecutor线程

转载 作者:行者123 更新时间:2023-11-28 22:27:45 35 4
gpt4 key购买 nike

关闭 Tomcat 时挂起。线程转储显示 8 个仍在运行的非守护线程,例如:

"SimpleAsyncTaskExecutor-1" #191 prio=5 os_prio=0      tid=0x00007fb138cfa000 nid=0x1e8c waiting on condition    [0x00007fb137bfa000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000e03e5198> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.nextMessage(BlockingQueueConsumer.java:359)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1000)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:989)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:82)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1103)
at java.lang.Thread.run(Thread.java:745)

当我通过 intellij 运行应用程序时,这些线程没有启动,并且通过 intellij 完成时正确关闭。它们仅在使用启动 shell 脚本启动 Web 应用程序时启动。

我如何确定是什么原因导致创建这些线程以及为什么它们不会关闭?

更新:这是我的项目的 web.xml。

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">

<absolute-ordering/>

<display-name>Test Web</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:spring/app-context.xml
</param-value>
</context-param>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>

<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>

<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>corsFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>corsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>etagFilter</filter-name>
<filter-class>org.springframework.web.filter.ShallowEtagHeaderFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>etagFilter</filter-name>
<url-pattern>/resource/*</url-pattern>
</filter-mapping>

<session-config>
<session-timeout>60</session-timeout>
</session-config>

最佳答案

这意味着应用程序上下文未正确关闭。这些线程在 SimpleMessageListenerContainer 中用于向监听器传递消息。

您如何加载应用程序上下文?如果您在代码中执行此操作,则您有责任close() 上下文以停止容器。

在 Web 容器中,上下文应由 DispatcherServletContextLoaderListenerWebApplicationInitializer 加载,以便关闭

关于tomcat - Spring rabbit启动不让Tomcat关闭的SimpleAsyncTaskExecutor线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35024264/

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