From 373e64b3eb30207f5d5006abf3dcc6ce484d072c Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 3 Oct 2013 07:41:57 -0700 Subject: [PATCH] improve thread pool rejection message --- .../common/util/concurrent/EsAbortPolicy.java | 11 ++++++++++- .../common/util/concurrent/SizeBlockingQueue.java | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/common/util/concurrent/EsAbortPolicy.java b/src/main/java/org/elasticsearch/common/util/concurrent/EsAbortPolicy.java index 5a2b4eaa5da..da86a0f1d08 100644 --- a/src/main/java/org/elasticsearch/common/util/concurrent/EsAbortPolicy.java +++ b/src/main/java/org/elasticsearch/common/util/concurrent/EsAbortPolicy.java @@ -49,7 +49,16 @@ public class EsAbortPolicy implements XRejectedExecutionHandler { } } rejected.inc(); - throw new EsRejectedExecutionException("rejected execution of [" + r.getClass().getName() + "]"); + StringBuilder sb = new StringBuilder("rejected execution "); + if (executor.isShutdown()) { + sb.append("(shutting down) "); + } else { + if (executor.getQueue() instanceof SizeBlockingQueue) { + sb.append("(queue capacity ").append(((SizeBlockingQueue) executor.getQueue()).capacity()).append(") "); + } + } + sb.append("on ").append(r.toString()); + throw new EsRejectedExecutionException(sb.toString()); } @Override diff --git a/src/main/java/org/elasticsearch/common/util/concurrent/SizeBlockingQueue.java b/src/main/java/org/elasticsearch/common/util/concurrent/SizeBlockingQueue.java index 043e48dfa41..c11fb32d459 100644 --- a/src/main/java/org/elasticsearch/common/util/concurrent/SizeBlockingQueue.java +++ b/src/main/java/org/elasticsearch/common/util/concurrent/SizeBlockingQueue.java @@ -51,6 +51,10 @@ public class SizeBlockingQueue extends AbstractQueue implements BlockingQu return size.get(); } + public int capacity() { + return this.capacity; + } + @Override public Iterator iterator() { final Iterator it = queue.iterator();