Task executor Spring integration - Subsequent service activators are executed as a part of the pool

∥☆過路亽.° 提交于 2019-12-25 00:39:14

问题


I am wrting a spring application where I am using 2 task executors. So structure of my code is as below

<!--
Web gatherer Configuration 
-->

<int:channel id="web-gatherer-channel">
    <int:queue capacity="10"/>
</int:channel>
<task:executor id="webGathererExecutor" pool-size="10" queue-capacity="10"/>
<int:service-activator input-channel="web-gatherer-channel" ref="webGatherer" method="getData"
                       output-channel="aggregator-router-channel">
    <int:poller task-executor="webGathererExecutor" fixed-delay="500">
    </int:poller>
</int:service-activator>


<!--
    Webgatherer  Configuration - END
-->

 <!--
SQL Gatherer Configuration - Start
-->
<int:channel id="sql-gatherer-channel">
    <int:queue capacity="10"/>
</int:channel>
<task:executor id="sqlGathererExecutor" pool-size="10" queue-capacity="10"/>
<int:service-activator input-channel="sql-gatherer-channel" ref="sqlGatherer" method="getData"
                       output-channel="aggregator-router-channel">
    <int:poller task-executor="sqlGathererExecutor" fixed-delay="500">
    </int:poller>
</int:service-activator>


<!--
SQL Gatherer Configuration - END
-->
 <int:chain input-channel="aggregator-router-channel">
    <int:aggregator ref="aggregator" method="aggregate" message-store="resultMessageStore"
                    release-strategy="gathererRelease"
                    correlation-strategy="gathererCorrelationStrategy"
                    correlation-strategy-method="getCorrelationKey">
    </int:aggregator>

    <int:router ref="generatorRouter" method="route"/>
</int:chain>

<int:chain input-channel="XLS-channel" output-channel="mailSender-channel">
    <int:service-activator  ref="xlsGenerator" method="generate"/>
</int:chain>

So the flow is as below

Message -> splitter - > 1. Web gatherer 2. SQL gatherer -> Aggrgator -> XLS generator

Currently my XLS service activator should run independently But in logs I can see it is running under one of the task executor which is random.

JxlsGenerator:sqlGathererExecutor-4 transformXLS execution in 166 ms

I am not able to understand why it is running as part of the task-executor pool.

Any help is appreciated.


回答1:


That's a result of the <int:aggregator>. It receives messages from different threads and when it is ready to release a group, it collects a result and emits it from the thread it has met a release condition. That's how your XLS-channel is called or from one or from another thread.

Well, actually any code in Java is called from some thread. When we develop single-threaded app with only main(), all the code is called from that main thread. If you don't change thread, the program is performed in the current thread.

If you would like to have XLS-channel on it own, independent thread, then consider to make this channel as an <executor>: https://docs.spring.io/spring-integration/docs/5.0.5.RELEASE/reference/html/messaging-channels-section.html#channel-configuration-executorchannel.

And also read about Java threading model.



来源:https://stackoverflow.com/questions/50250998/task-executor-spring-integration-subsequent-service-activators-are-executed-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!