{"record":{"id":"1b6917f353f3603c","repo":"Netflix/Hystrix","slug":"rejected-command-because-thread-pool-queuesize-is","errorCode":null,"errorMessage":"Rejected command because thread-pool queueSize is at rejection threshold.","messagePattern":"Rejected command because thread-pool queueSize is at rejection threshold\\.","errorType":"exception","errorClass":"RejectedExecutionException","httpStatus":null,"severity":"warning","filePath":"hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixContextScheduler.java","lineNumber":93,"sourceCode":"        private HystrixContextSchedulerWorker(Worker actualWorker) {\n            this.worker = actualWorker;\n        }\n\n        @Override\n        public void unsubscribe() {\n            worker.unsubscribe();\n        }\n\n        @Override\n        public boolean isUnsubscribed() {\n            return worker.isUnsubscribed();\n        }\n\n        @Override\n        public Subscription schedule(Action0 action, long delayTime, TimeUnit unit) {\n            if (threadPool != null) {\n                if (!threadPool.isQueueSpaceAvailable()) {\n                    throw new RejectedExecutionException(\"Rejected command because thread-pool queueSize is at rejection threshold.\");\n                }\n            }\n            return worker.schedule(new HystrixContextSchedulerAction(concurrencyStrategy, action), delayTime, unit);\n        }\n\n        @Override\n        public Subscription schedule(Action0 action) {\n            if (threadPool != null) {\n                if (!threadPool.isQueueSpaceAvailable()) {\n                    throw new RejectedExecutionException(\"Rejected command because thread-pool queueSize is at rejection threshold.\");\n                }\n            }\n            return worker.schedule(new HystrixContextSchedulerAction(concurrencyStrategy, action));\n        }\n\n    }\n\n    private static class ThreadPoolScheduler extends Scheduler {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/Netflix/Hystrix/blob/5ce3bc58c38e7ca60ef2fe0e516e390e294ad941/hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixContextScheduler.java#L75-L111","documentation":"When a HystrixCommand runs with thread isolation, work is scheduled through HystrixContextScheduler. Before handing a task to the worker, the scheduler checks HystrixThreadPool.isQueueSpaceAvailable(); when the pool's queue has reached its rejection threshold (queueSizeRejectionThreshold), this RejectedExecutionException is thrown. Hystrix translates it into a THREAD_POOL_REJECTED / fallback outcome rather than a crash.","triggerScenarios":"Scheduling a semaphore- or thread-isolated command's asynchronous work (queue(), observe(), toObservable() subscription) when the pool's underlying queue size >= queueSizeRejectionThreshold; bursty traffic with a small maxQueueSize or low rejection threshold.","commonSituations":"Thread pool saturated under load spikes: maxQueueSize=-1 (SynchronousQueue, no buffering) or default queueSizeRejectionThreshold=5 with fast producers; commands with long run() times backing up the pool; bulkheading configured too small for the request rate.","solutions":["Tune the pool: raise corePoolSize/maximumSize and queueSizeRejectionThreshold via hystrix.threadpool.<key>.coreSize / maximumSize / maxQueueSize / queueSizeRejectionThreshold properties.","Reduce command execution time or move blocking work out of run() so pool threads free up faster.","Implement a getFallback() so rejections degrade gracefully instead of propagating failure.","Shed load upstream (rate limiting, bulkheading at the caller) so fewer tasks reach a saturated pool."],"exampleFix":"# before\nhystrix.threadpool.orders.coreSize=10\nhystrix.threadpool.orders.maxQueueSize=-1\n\n# after\nhystrix.threadpool.orders.coreSize=25\nhystrix.threadpool.orders.maximumSize=40\nhystrix.threadpool.orders.maxQueueSize=100\nhystrix.threadpool.orders.queueSizeRejectionThreshold=50","handlingStrategy":"fallback","validationCode":"// Check saturation before launching work (best-effort)\nHystrixThreadPoolMetrics m = HystrixThreadPoolMetrics.getInstance(\n        HystrixThreadPoolKey.Factory.asKey(\"orders\"), null, null);\n// simpler: rely on Hystrix itself - implement getFallback() so rejection degrades gracefully","typeGuard":null,"tryCatchPattern":"try {\n    String r = new MyCommand(key).queue().get(2, TimeUnit.SECONDS);\n} catch (ExecutionException e) {\n    if (e.getCause() instanceof HystrixRuntimeException\n            && ((HystrixRuntimeException) e.getCause()).getFailureType() == HystrixRuntimeException.FailureType.REJECTED) {\n        return degradedValue(); // thread pool rejected - back off\n    }\n    throw e;\n}","preventionTips":["Size thread pools from measured throughput x latency, not defaults.","Set maxQueueSize and queueSizeRejectionThreshold deliberately for burst tolerance.","Always implement getFallback() for commands that must not hard-fail under load.","Watch Hystrix thread-pool metrics (queue size, rejection count) and alert before saturation."],"tags":["hystrix","thread-pool","rejection","backpressure"],"backgroundTag":null,"analyzedSha":"5ce3bc58c38e7ca60ef2fe0e516e390e294ad941","analyzedAt":"2026-08-14T10:55:35.600Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}