问题
I have below configuration where I am trying to process at most 5 requests concurrently. Each request takes much different time to process. What I am noticing it starts processing 5 tasks which is great but when one of the task completes, it does not immediately takes another task, in fact it is waiting for all 5 tasks to complete and then only it starts next 5 tasks. So I am getting some sort of batch processing behavior. May be I have not configured properly, please help to correct this. I want to start the next task immediately as soon as the thread is done processing one.
I can increase the queue capacity and in that case it does start the next task but I only want to invoke my inbound message provider when I am ready to process the message, not to just hold it in task executor queue.
<int:inbound-channel-adapter ref="feeder" channel="in">
<int:poller fixed-rate="100">
</int:poller>
</int:inbound-channel-adapter>
<int:bridge input-channel="in" output-channel="out" />
<task:executor id="taskExecutor" pool-size="1-5" keep-alive="120"
queue-capacity="0" rejection-policy="CALLER_RUNS"/>
<int:channel id="out">
<int:dispatcher task-executor="taskExecutor"/>
</int:channel>
<int:service-activator input-channel="out" output-channel="replyChannel"
ref="processor" method="process"/>
回答1:
The problem is your 'caller runs' policy; this means the polling thread runs one of your tasks (#6) and won't poll again until that task completes.
You really need to use a CallerBlocks policy - we added one to Spring Integration in 3.0.3 and 4.0.1.
You would need to wire up the TaskExecutor as a <bean/>; the namespace doesn't support custom policies.
EDIT:
Created JIRA Issue.
来源:https://stackoverflow.com/questions/25796527/task-executor-will-not-run-next-task-immediately