![](/img/trans.png)
[英]Spring integration - Task executor with SimpleAsyncTaskExecutor
[英]Spring Integration: Application leaking SimpleAsyncTaskExecutor threads?
我們在生產中有一個Spring應用程序,看來它正在泄漏線程。
當我執行線程轉儲時,我看到以下似乎正在等待的線程。 下面是一個示例,但是有成千上萬個
"SimpleAsyncTaskExecutor-1801" prio=10 tid=0x00007fa668413800 nid=0x376c waiting on condition [0x00007fa4fbaff000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000007777e2ba8> (a java.util.concurrent.CountDownLatch$Sync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:834)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:994)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1303)
at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:236)
at org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel.receive(MessagingTemplate.java:415)
at org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel.receive(MessagingTemplate.java:409)
at org.springframework.integration.core.MessagingTemplate.doReceive(MessagingTemplate.java:317)
at org.springframework.integration.core.MessagingTemplate.doSendAndReceive(MessagingTemplate.java:341)
at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:255)
at org.springframework.integration.core.MessagingTemplate.convertSendAndReceive(MessagingTemplate.java:290)
at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:224)
at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:203)
at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:306)
at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:269)
at org.springframework.integration.gateway.GatewayProxyFactoryBean.access$200(GatewayProxyFactoryBean.java:71)
at org.springframework.integration.gateway.GatewayProxyFactoryBean$AsyncInvocationTask.call(GatewayProxyFactoryBean.java:499)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.lang.Thread.run(Thread.java:745)
最終,它達到導致服務器無響應的狀態,只有重啟才能將其恢復。
這似乎與Spring Integration Gateway有關,該網關發送了一條消息,並在等待一些從未得到的答案。 我們應用程序中唯一使用此消息的地方是一個通知通道,該通知通道使用服務接口將這些消息發送(發布)到RabbitMQ交換。
這是服務接口代碼:
@Component
public interface INotificationSender {
Future<Void> sendNotification(@Payload Object notification,
@Header("routingKey") String routingKey,
@Header("notificationType") String type);
}
這是相關的彈簧配置:
<!-- Spring Integration RabbitMQ adapter -->
<rabbit:template
id="amqpTemplate"
connection-factory="notificationConnectionFactory" />
<rabbit:connection-factory
id="notificationConnectionFactory"
addresses="${notificationChannel.rabbitHost1}:${notificationChannel.rabbitPort}, ${notificationChannel.rabbitHost2}:${notificationChannel.rabbitPort}"
username="${notificationChannel.rabbitUsername}"
password="${notificationChannel.rabbitPassword}"
virtual-host="${notificationChannel.rabbitVirtualHost}"/>
<rabbit:topic-exchange
name="notificationExchange"/>
<!-- Spring Integration AMQP -->
<int-amqp:outbound-channel-adapter
id="notificationChannelAdapter"
channel="notificationChannelEnc"
exchange-name="notificationExchange"
routing-key-expression="headers['routingKey']"
mapped-request-headers="STANDARD_REQUEST_HEADERS, notificationType"/>
<!-- Spring Integration Core -->
<int:channel
id="notificationChannelEnc">
<int:interceptors>
<int:wire-tap channel="loggingChannel" />
</int:interceptors>
</int:channel>
<int:channel id="notificationChannel"/>
<int:object-to-json-transformer
id="NotificationEncoder"
content-type="text/x-json"
input-channel="notificationChannel"
output-channel="notificationChannelEnc"/>
<int:gateway
id="notificationGateway"
default-request-channel="notificationChannel"
service-interface="com.ericsson.ericloud.commander.notification.sender.INotificationSender"/>
我們正在使用Spring版本3.2.3.RELEASE和Spring Integration版本3.0.0.M2
有人知道如何處理這些線程並使這些線程正確終止嗎?
謝謝,/ Sebastien
您的Future<Void>
是一個瓶頸。
我可以猜到您要異步發送通知,而不必等待任何回復。 但是無論如何, Gateway
嘗試等待答復,因為它將“ Future
視為啟動異步過程的提示。
為了克服它,您必須將return更改為簡單的void
並將ExecutorChannel
用作網關的default-request-channel
。
請參閱《 參考手冊》中的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.