线程池 – java.util.concurrent.RejectedExecutionException

huangapple go评论77阅读模式
英文:

ThreadPool - java.util.concurrent.RejectedExecutionException

问题

我每次收到更多调用时都会出现 java.util.concurrent.RejectedExecutionException

我们将 coreSize 定义为 10,maximumSize 定义为 25,但是我们甚至在只有 10 个线程时就出现了此异常。我们应该在 25 个线程后才会出现这个异常,对吗?我是否漏掉了什么?请帮我解决一下。

hystrix.threadpool.servicename.coreSize=10
hystrix.threadpool.servicename.maximumSize=25

异常堆栈:

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@74132085 rejected from java.util.concurrent.ThreadPoolExecutor@21e44930[Running, pool size = 10, active threads = 10, queued tasks = 0, completed tasks = 23666917]
	at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)
	at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
	at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379)
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
	at com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler$ThreadPoolWorker.schedule(HystrixContextScheduler.java:172)
	at com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler$HystrixContextSchedulerWorker.schedule(HystrixContextScheduler.java:106)
	at rx.internal.operators.OperatorSubscribeOn.call(OperatorSubscribeOn.java:50)
	at rx.internal.operators.OperatorSubscribeOn.call(OperatorSubscribeOn.java:30)
	at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
	...
英文:

I am getting java.util.concurrent.RejectedExecutionException whenever we are getting more calls.

We have defined coreSize as 10 and maximumSize as 25, but we are getting this exception for 10 threads itself. We should get this exception after 25 threads Right? Am I missing anything ? Could you please help me to fix this ?

hystrix.threadpool.servicename.coreSize=10
hystrix.threadpool.servicename.maximumSize=25

Exception trace :

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@74132085 rejected from java.util.concurrent.ThreadPoolExecutor@21e44930[Running, pool size = 10, active threads = 10, queued tasks = 0, completed tasks = 23666917]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler$ThreadPoolWorker.schedule(HystrixContextScheduler.java:172)
at com.netflix.hystrix.strategy.concurrency.HystrixContextScheduler$HystrixContextSchedulerWorker.schedule(HystrixContextScheduler.java:106)
at rx.internal.operators.OperatorSubscribeOn.call(OperatorSubscribeOn.java:50)
at rx.internal.operators.OperatorSubscribeOn.call(OperatorSubscribeOn.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10346)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10346)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10346)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10346)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10346)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10346)
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
at rx.Observable.unsafeSubscribe(Observable.java:10346)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10346)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10346)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10346)
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.subscribe(Observable.java:10442)
at rx.Observable.subscribe(Observable

答案1

得分: 1

RejectedExecutionException发生在线程池无法接受任何新任务时。

如果线程池中有一些空闲线程,它会立即开始执行任务。否则,任务将排队在线程池内的一个“队列”中。根据线程池的实现,这个队列可能是有界的。在这种情况下,当提交新任务时,由于无法将其排队,线程池会抛出RejectedExecutionException。

我认为在Hystrix中不能有无界队列。您需要根据HystrixThreadPoolProperties中的负载确定适当的队列大小。

英文:

RejectedExecutionException occurs when the thread pool is not able to accept any new tasks.

If some idle thread is available in the thread pool, it starts task execution immediately. Else the task is queued in a queue inside the thread pool. Depending on the thread pool implementation, this queue could be bounded. In such a scenario, when a new task is submitted, since it cannot be queued the thread pool throws RejectedExecutionException.

I don't think you can have unbounded queues in hystrix. You need to determine the appropriate queue size depending on your load in HystrixThreadPoolProperties.

答案2

得分: 1

你必须设置 hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize=true,如果你想覆盖 maximumSize。

英文:

You have to set hystrix.threadpool.default.allowMaximumSizeToDivergeFromCoreSize=true if you want to overide maximumSize

huangapple
  • 本文由 发表于 2020年9月2日 16:16:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63701401.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定