lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r1673471 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/cloud/ solr/core/src/java/org/apache/solr/core/ solr/core/src/java/org/apache/solr/handler/ solr/core/src/java/org/apache/solr/handler/admi...
Date Tue, 14 Apr 2015 17:06:43 GMT
Author: shalin
Date: Tue Apr 14 17:06:42 2015
New Revision: 1673471

URL: http://svn.apache.org/r1673471
Log:
SOLR-7381: MDC keys are now exposed in thread names automatically so that a thread dump can
give hints on what the thread was doing

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/ZkContainer.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java
    lucene/dev/branches/branch_5x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Tue Apr 14 17:06:42 2015
@@ -81,7 +81,9 @@ Other Changes
 * SOLR-7381: Improve logging by adding node name in MDC in SolrCloud mode and adding MDC
to
   all thread pools. A new MDCAwareThreadPoolExecutor is introduced and usages of
   Executors#newFixedThreadPool, #newSingleThreadExecutor, #newCachedThreadPool as well as
-  ThreadPoolExecutor directly is now forbidden in Solr. (shalin)
+  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.
+  (shalin)
 
 * SOLR-7384: Fix spurious failures in FullSolrCloudDistribCmdsTest. (shalin)
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/OverseerAutoReplicaFailoverThread.java
Tue Apr 14 17:06:42 2015
@@ -33,6 +33,7 @@ import org.apache.solr.core.CloudConfig;
 import org.apache.solr.update.UpdateShardHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 
 import java.io.Closeable;
 import java.util.ArrayList;
@@ -245,14 +246,19 @@ public class OverseerAutoReplicaFailover
       // need an async request - full shard goes down leader election
       final String coreName = badReplica.replica.getStr(ZkStateReader.CORE_NAME_PROP);
       log.debug("submit call to {}", createUrl);
-      updateExecutor.submit(new Callable<Boolean>() {
-        
-        @Override
-        public Boolean call() {
-          return createSolrCore(collection, createUrl, dataDir, ulogDir, coreNodeName, coreName);
-        }
-      });
-      
+      MDC.put("OverseerAutoReplicaFailoverThread.createUrl", createUrl);
+      try {
+        updateExecutor.submit(new Callable<Boolean>() {
+
+          @Override
+          public Boolean call() {
+            return createSolrCore(collection, createUrl, dataDir, ulogDir, coreNodeName,
coreName);
+          }
+        });
+      } finally {
+        MDC.remove("OverseerAutoReplicaFailoverThread.createUrl");
+      }
+
       // wait to see state for core we just created
       boolean success = ClusterStateUtil.waitToSeeLiveReplica(zkStateReader, collection,
coreNodeName, createUrl, 30000);
       if (!success) {

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/ZkContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/ZkContainer.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/ZkContainer.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/core/ZkContainer.java
Tue Apr 14 17:06:42 2015
@@ -28,6 +28,7 @@ import java.util.concurrent.ExecutorServ
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeoutException;
 
+import org.apache.log4j.MDC;
 import org.apache.solr.cloud.CurrentCoreDescriptorProvider;
 import org.apache.solr.cloud.SolrZkServer;
 import org.apache.solr.cloud.ZkController;
@@ -36,11 +37,14 @@ import org.apache.solr.common.cloud.Repl
 import org.apache.solr.common.cloud.ZkConfigManager;
 import org.apache.solr.common.cloud.ZooKeeperException;
 import org.apache.solr.common.util.ExecutorUtil;
+import org.apache.solr.logging.MDCUtils;
 import org.apache.solr.util.DefaultSolrThreadFactory;
 import org.apache.zookeeper.KeeperException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
+
 public class ZkContainer {
   protected static Logger log = LoggerFactory.getLogger(ZkContainer.class);
   
@@ -195,14 +199,19 @@ public class ZkContainer {
             SolrException.log(log, "", e);
           }
         }
-      
+
     };
     
     if (zkController != null) {
-      if (background) {
-        coreZkRegister.execute(thread);
-      } else {
-        thread.run();
+      MDCUtils.setCore(core.getName());
+      try {
+        if (background) {
+          coreZkRegister.execute(thread);
+        } else {
+          thread.run();
+        }
+      } finally {
+        MDC.remove(CORE_NAME_PROP);
       }
     }
   }

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java
Tue Apr 14 17:06:42 2015
@@ -90,6 +90,7 @@ import org.apache.solr.util.RefCounted;
 import org.apache.solr.util.plugin.SolrCoreAware;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 
 import static org.apache.solr.common.params.CommonParams.NAME;
 
@@ -427,8 +428,17 @@ public class ReplicationHandler extends
     }
 
     RestoreCore restoreCore = new RestoreCore(core, location, name);
-    restoreFuture = restoreExecutor.submit(restoreCore);
-    currentRestoreName = name;
+    try {
+      MDC.put("RestoreCore.core", core.getName());
+      MDC.put("RestoreCore.backupLocation", location);
+      MDC.put("RestoreCore.backupName", name);
+      restoreFuture = restoreExecutor.submit(restoreCore);
+      currentRestoreName = name;
+    } finally {
+      MDC.remove("RestoreCore.core");
+      MDC.remove("RestoreCore.backupLocation");
+      MDC.remove("RestoreCore.backupName");
+    }
   }
 
   private NamedList<Object> getRestoreStatus() {

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
Tue Apr 14 17:06:42 2015
@@ -84,6 +84,7 @@ import org.apache.solr.util.RefCounted;
 import org.apache.zookeeper.KeeperException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 
 import static org.apache.solr.common.cloud.DocCollection.DOC_ROUTER;
 import static org.apache.solr.common.params.CommonParams.NAME;
@@ -191,7 +192,16 @@ public class CoreAdminHandler extends Re
       handleRequestInternal(req, rsp, action);
     } else {
       ParallelCoreAdminHandlerThread parallelHandlerThread = new ParallelCoreAdminHandlerThread(req,
rsp, action, taskObject);
-      parallelExecutor.execute(parallelHandlerThread);
+      try {
+        MDC.put("CoreAdminHandler.asyncId", taskId);
+        if (action != null) {
+          MDC.put("CoreAdminHandler.action", action.name());
+        }
+        parallelExecutor.execute(parallelHandlerThread);
+      } finally {
+        MDC.remove("CoreAdminHandler.asyncId");
+        MDC.remove("CoreAdminHandler.action");
+      }
     }
   }
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandler.java
Tue Apr 14 17:06:42 2015
@@ -60,6 +60,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Strings;
+import org.slf4j.MDC;
 
 public class HttpShardHandler extends ShardHandler {
 
@@ -239,7 +240,18 @@ public class HttpShardHandler extends Sh
       }
     };
 
-    pending.add( completionService.submit(task) );
+    try {
+      if (shard != null)  {
+        MDC.put("ShardRequest.shards", shard);
+      }
+      if (urls != null && !urls.isEmpty())  {
+        MDC.put("ShardRequest.urlList", urls.toString());
+      }
+      pending.add( completionService.submit(task) );
+    } finally {
+      MDC.remove("ShardRequest.shards");
+      MDC.remove("ShardRequest.urlList");
+    }
   }
   
   /**

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java
Tue Apr 14 17:06:42 2015
@@ -72,6 +72,7 @@ import org.apache.solr.update.VersionInf
 import org.apache.zookeeper.KeeperException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -933,7 +934,12 @@ public class DistributedUpdateProcessor
               maxTries,
               cloudDesc.getCoreNodeName()); // core node name of current leader
       ExecutorService executor = coreContainer.getUpdateShardHandler().getUpdateExecutor();
-      executor.execute(lirThread);
+      try {
+        MDC.put("DistributedUpdateProcessor.replicaUrlToRecover", error.req.node.getNodeProps().getCoreUrl());
+        executor.execute(lirThread);
+      } finally {
+        MDC.remove("DistributedUpdateProcessor.replicaUrlToRecover");
+      }
     }
 
     if (replicationTracker != null) {

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
(original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
Tue Apr 14 17:06:42 2015
@@ -54,6 +54,7 @@ import org.apache.solr.common.util.StrUt
 import org.apache.zookeeper.KeeperException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 
 import java.io.IOException;
 import java.net.ConnectException;
@@ -110,7 +111,7 @@ public class CloudSolrClient extends Sol
   private boolean parallelUpdates = true;
   private ExecutorService threadPool = ExecutorUtil
       .newMDCAwareCachedThreadPool(new SolrjNamedThreadFactory(
-          "CloudSolrServer ThreadPool"));
+          "CloudSolrClient ThreadPool"));
   private String idField = "id";
   public static final String STATE_VERSION = "_stateVer_";
   private final Set<String> NON_ROUTABLE_PARAMS;
@@ -591,12 +592,17 @@ public class CloudSolrClient extends Sol
       for (final Map.Entry<String, LBHttpSolrClient.Req> entry : routes.entrySet())
{
         final String url = entry.getKey();
         final LBHttpSolrClient.Req lbRequest = entry.getValue();
-        responseFutures.put(url, threadPool.submit(new Callable<NamedList<?>>()
{
-          @Override
-          public NamedList<?> call() throws Exception {
-            return lbClient.request(lbRequest).getResponse();
-          }
-        }));
+        try {
+          MDC.put("CloudSolrClient.url", url);
+          responseFutures.put(url, threadPool.submit(new Callable<NamedList<?>>()
{
+            @Override
+            public NamedList<?> call() throws Exception {
+              return lbClient.request(lbRequest).getResponse();
+            }
+          }));
+        } finally {
+          MDC.remove("CloudSolrClient.url");
+        }
       }
 
       for (final Map.Entry<String, Future<NamedList<?>>> entry: responseFutures.entrySet())
{

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
(original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
Tue Apr 14 17:06:42 2015
@@ -42,6 +42,7 @@ import org.apache.solr.common.util.Named
 import org.apache.solr.common.util.SolrjNamedThreadFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 
 import java.io.IOException;
 import java.io.OutputStream;
@@ -343,9 +344,14 @@ public class ConcurrentUpdateSolrClient
           if (runners.isEmpty() || (queue.remainingCapacity() < queue.size() &&
runners.size() < threadCount))
           {
             // We need more runners, so start a new one.
-            Runner r = new Runner();
-            runners.add(r);
-            scheduler.execute(r);
+            MDC.put("ConcurrentUpdateSolrClient.url", client.getBaseURL());
+            try {
+              Runner r = new Runner();
+              runners.add(r);
+              scheduler.execute(r);
+            } finally {
+              MDC.remove("ConcurrentUpdateSolrClient.url");
+            }
           } else {
             // break out of the retry loop if we added the element to the queue
             // successfully, *and*
@@ -402,9 +408,14 @@ public class ConcurrentUpdateSolrClient
           if (queueSize > 0) {
             log.warn("No more runners, but queue still has "+
               queueSize+" adding more runners to process remaining requests on queue");
-            Runner r = new Runner();
-            runners.add(r);
-            scheduler.execute(r);
+            MDC.put("ConcurrentUpdateSolrClient.url", client.getBaseURL());
+            try {
+              Runner r = new Runner();
+              runners.add(r);
+              scheduler.execute(r);
+            } finally {
+              MDC.remove("ConcurrentUpdateSolrClient.url");
+            }
           }
         }
       }

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
(original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
Tue Apr 14 17:06:42 2015
@@ -57,6 +57,7 @@ import org.apache.solr.common.util.Named
 import org.apache.solr.common.util.SolrjNamedThreadFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -262,6 +263,7 @@ public class HttpSolrClient extends Solr
     final HttpRequestBase method = createMethod(request, null);
     ExecutorService pool = ExecutorUtil.newMDCAwareFixedThreadPool(1, new SolrjNamedThreadFactory("httpUriRequest"));
     try {
+      MDC.put("HttpSolrClient.url", baseUrl);
       mrr.future = pool.submit(new Callable<NamedList<Object>>(){
 
         @Override
@@ -271,6 +273,7 @@ public class HttpSolrClient extends Solr
  
     } finally {
       pool.shutdown();
+      MDC.remove("HttpSolrClient.url");
     }
     assert method != null;
     mrr.httpUriRequest = method;

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
(original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrClient.java
Tue Apr 14 17:06:42 2015
@@ -27,6 +27,7 @@ import org.apache.solr.common.params.Sol
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SolrjNamedThreadFactory;
 import org.apache.solr.common.SolrException;
+import org.slf4j.MDC;
 
 import java.io.IOException;
 import java.lang.ref.WeakReference;
@@ -320,11 +321,16 @@ public class LBHttpSolrClient extends So
         continue;
       }
       rsp.server = serverStr;
-      HttpSolrClient client = makeSolrClient(serverStr);
-
-      ex = doRequest(client, req, rsp, isUpdate, false, null);
-      if (ex == null) {
-        return rsp; // SUCCESS
+      try {
+        MDC.put("LBHttpSolrClient.url", serverStr);
+        HttpSolrClient client = makeSolrClient(serverStr);
+
+        ex = doRequest(client, req, rsp, isUpdate, false, null);
+        if (ex == null) {
+          return rsp; // SUCCESS
+        }
+      } finally {
+        MDC.remove("LBHttpSolrClient.url");
       }
     }
 

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java?rev=1673471&r1=1673470&r2=1673471&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
(original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/common/util/ExecutorUtil.java
Tue Apr 14 17:06:42 2015
@@ -106,6 +106,8 @@ public class ExecutorUtil {
 
   public static class MDCAwareThreadPoolExecutor extends ThreadPoolExecutor {
 
+    private static final int MAX_THREAD_NAME_LEN = 512;
+
     public MDCAwareThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler
handler) {
       super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory,
handler);
     }
@@ -125,12 +127,18 @@ public class ExecutorUtil {
     @Override
     public void execute(final Runnable command) {
       final Map<String, String> submitterContext = MDC.getCopyOfContextMap();
+      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);
       super.execute(new Runnable() {
         @Override
         public void run() {
           Map<String, String> threadContext = MDC.getCopyOfContextMap();
-          if (submitterContext != null) {
+          final Thread currentThread = Thread.currentThread();
+          final String oldName = currentThread.getName();
+          if (submitterContext != null && !submitterContext.isEmpty()) {
             MDC.setContextMap(submitterContext);
+            currentThread.setName(oldName + "-processing-" + submitterContextStr);
           } else {
             MDC.clear();
           }
@@ -142,6 +150,7 @@ public class ExecutorUtil {
             } else {
               MDC.clear();
             }
+            currentThread.setName(oldName);
           }
         }
       });



Mime
View raw message