Task executor will not run next task immediately

痴心易碎 提交于 2019-12-12 02:57:17

问题


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

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