2
我有一個簡單的彈簧集成應用程序,我試圖將任務發佈到隊列通道,然後讓工作人員拿起任務並執行它。 (來自具有多個併發工作者的池)。彈簧集成 - 隊列通道+服務激活器輪詢器耗盡線程池
我發現線程池很快耗盡,任務被拒絕。
這裏是我的配置:
<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消息代理,只是內部彈簧消息通道。
我一直沒有能夠找到一個在香草泉渠道concurrent-consumer
概念的類比。
而且,我已經通過了加里·拉塞爾的建議配置:
爲了避免這種情況,只需將接收超時設置爲0的
<poller/>
儘管如此,我仍然得到池枯竭了。
這個目標的正確配置是什麼?
順便說一句 - 其他兩種味道在這裏建議我的配置是錯誤的:
- 我爲什麼被拒異常時
rejection-policy
是CALLER_RUNS
? - 當
queued tasks = 1000
發生異常時開始。鑑於執行者沒有隊列容量,隊列不應無限制嗎?顯示
異常堆棧跟蹤:
[Mon Dec 2013 17:44:57.172] ERROR [task-scheduler-6] (org.springframework.integration.handler.LoggingHandler:126) - org.springframework.core.task.TaskRejectedException: Executor [[email protected][Running, pool size = 20, active threads = 20, queued tasks = 1000, completed tasks = 48]] did not accept task: o[email protected]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 o[email protected]a5798e rejected from [email protected][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
Downvoter - 謹慎評論爲什麼? –