KAFKA-7880:Naming worker thread by task id
Name worker thread to include task id
Change Connect's `WorkerTask` to name the thread using the `task-thread-<connectorTaskId>` pattern.
Reviewers: Randall Hauch
@@ -51,6 +51,7 @@ import java.util.concurrent.TimeUnit;
*/
abstract class WorkerTask implements Runnable {
private static final Logger log = LoggerFactory.getLogger(WorkerTask.class);
+ private static final String THREAD_NAME_PREFIX = "task-thread-";
protected final ConnectorTaskId id;
private final TaskStatus.Listener statusListener;
@@ -215,7 +216,9 @@ abstract class WorkerTask implements Runnable {
@Override
public void run() {
ClassLoader savedLoader = Plugins.compareAndSwapLoaders(loader);
+ String savedName = Thread.currentThread().getName();
try {
+ Thread.currentThread().setName(THREAD_NAME_PREFIX + id);
doRun();
onShutdown();
} catch (Throwable t) {
@@ -225,6 +228,7 @@ abstract class WorkerTask implements Runnable {
throw (Error) t;
} finally {
try {
+ Thread.currentThread().setName(savedName);
Plugins.compareAndSwapLoaders(savedLoader);
shutdownLatch.countDown();
} finally {
