首页 文章

Spring Integration - 队列通道服务激活器Poller耗尽线程池

提问于
浏览
2

我有一个简单的 spring 集成应用程序,我试图将任务发布到队列通道,然后让工作人员接受任务并执行它 . (来自具有多个并发工作者的池) .

我发现线程池很快耗尽,任务被拒绝 .

这是我的配置:

<int:annotation-config />
<task:annotation-driven executor="executor" scheduler="scheduler"/>
<task:executor id="executor" pool-size="5-20" rejection-policy="CALLER_RUNS" />
<task:scheduler id="scheduler" pool-size="5"/>


<int:gateway service-interface="com.example.MyGateway">
    <int:method name="queueForSync" request-channel="worker.channel" />
</int:gateway>
<int:channel id="worker.channel">
    <int:queue />
</int:channel>

<bean class="com.example.WorkerBean" id="workerBean" />
<int:service-activator ref="workerBean" method="doWork" input-channel="worker.channel">
    <int:poller fixed-delay="50" task-executor="executor" receive-timeout="0" />
</int:service-activator>

这个问题与我回答的另一个问题非常相似,here . 主要区别在于我没有在这里使用AMQP消息代理,只是内部 spring 消息通道 .

我无法在香草 spring 通道中找到 concurrent-consumer 概念的类比 .

而且,我采用了Gary Russell建议的配置:

要避免这种情况,只需在<poller />上将receive-timeout设置为0即可

尽管如此,我仍然让游泳池疲惫不堪 .

这个目标的正确配置是什么?

另外 - 这里有两个其他的气味表明我的配置错误:

  • 为什么 rejection-policyCALLER_RUNS 时我被拒绝了例外?

  • queued tasks = 1000 时会发生异常 . 鉴于's no queue-capacity on the executor, shouldn' t队列是无限的?

显示异常堆栈跟踪:

[Mon Dec 2013 17:44:57.172] ERROR [task-scheduler-6] (org.springframework.integration.handler.LoggingHandler:126) - org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@48e83911[Running, pool size = 20, active threads = 20, queued tasks = 1000, completed tasks = 48]] did not accept task: org.springframework.integration.util.ErrorHandlingTaskExecutor$1@a5798e
    at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:244)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:49)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:231)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.util.concurrent.RejectedExecutionException: Task org.springframework.integration.util.ErrorHandlingTaskExecutor$1@a5798e rejected from java.util.concurrent.ThreadPoolExecutor@48e83911[Running, pool size = 20, active threads = 20, queued tasks = 1000, completed tasks = 48]
    at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2048)
    at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:821)
    at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1372)
    at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:241)
    ... 11 more

1 回答

  • 0

    最好的猜测是你在上下文中的其他地方有另一个 executor bean .

    打开调试日志记录并查找 ...DefaultListableBeanFactory] Overriding bean definition for bean 'executor' .

    默认队列容量为 Integer.MAX_VALUE .

相关问题