Reputation: 95
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.
Upvotes: 0
Views: 929
Reputation: 121262
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.
Upvotes: 1