SOLR-7381: Uncaught exceptions thrown by tasks in the pool are logged along with submitter's stack trace

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1674593 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2015-04-19 03:48:22 +00:00
parent 04f870c172
commit e699256bbb
2 changed files with 9 additions and 1 deletions

View File

@ -158,6 +158,7 @@ Other Changes
Executors#newFixedThreadPool, #newSingleThreadExecutor, #newCachedThreadPool as well as
ThreadPoolExecutor directly is now forbidden in Solr. MDC keys are now exposed in thread
names automatically so that a thread dump can give hints on what the thread was doing.
Uncaught exceptions thrown by tasks in the pool are logged along with submitter's stack trace.
(shalin)
* SOLR-7384: Fix spurious failures in FullSolrCloudDistribCmdsTest. (shalin)

View File

@ -130,6 +130,7 @@ public class ExecutorUtil {
String ctxStr = submitterContext != null && !submitterContext.isEmpty() ?
submitterContext.toString().replace("/", "//") : "";
final String submitterContextStr = ctxStr.length() <= MAX_THREAD_NAME_LEN ? ctxStr : ctxStr.substring(0, MAX_THREAD_NAME_LEN);
final Exception submitterStackTrace = new Exception("Submitter stack trace");
super.execute(new Runnable() {
@Override
public void run() {
@ -144,8 +145,14 @@ public class ExecutorUtil {
}
try {
command.run();
} catch (Throwable t) {
if (t instanceof OutOfMemoryError) {
throw t;
}
log.error("Uncaught exception {} thrown by thread: {}", t, currentThread.getName(), submitterStackTrace);
throw t;
} finally {
if (threadContext != null) {
if (threadContext != null && !threadContext.isEmpty()) {
MDC.setContextMap(threadContext);
} else {
MDC.clear();