如果发生异常,Task Executor线程不会返回池

时间:2015-10-01 16:55:24

标签: java spring spring-integration threadpoolexecutor

当嵌套链失败并到达错误通道流时,任务执行程序线程阻塞并且不会返回到池。有没有办法表明流程已经到达并且需要将它们返回池中。

例如,分离器将有效载荷分成3条消息。消息作为 -

提供
message 1 - fileChannelTaskExecutor1
message 2 - fileChannelTaskExecutor2

如果"嵌套链"网关调用成功,第三条消息被提供给任何早先释放的执行者线程。

但是如果"嵌套链"网关调用失败并到达errChannel,上述执行程序线程块都没有返回池。因此,由于池中没有可用的线程,因此不会处理连续的消息(消息3)。

<bean id="fileChannelTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="2"/>
    <property name="daemon" value="false"/>
</bean>

<int:channel id="splitterResponseChannel">
    <int:dispatcher task-executor="fileChannelTaskExecutor"/>
</int:channel>

<int:splitter input-channel="splitterRequestChannel" output-channel="splitterResponseChannel" >

<int:chain input-channel="splitterResponseChannel">
    <int:gateway request-channel="nested-chain" error-channel="errChannel"/>
</int:chain>

<int:chain input-channel="errChannel" output-channel="nullChannel">
     .....
</int:chain>

1 个答案:

答案 0 :(得分:2)

此处的问题是单向nullChannel<int:gateway>请求/回复性质。

即使您向error-channel发送Exception,也应该将其重新抛出到调用中,或者从错误流中返回一些compensation消息。 另一方面,你最终会挂在网关上,永远等待回复。默认情况下,当然!

您可以针对此问题调整reply-timeout并在一段时间内将线程释放到池中,以防出现单向错误过程。

相关问题