From a4f3e72e7187e22f2772de542b877dece0fa4baa Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 30 Oct 2015 10:59:33 +0100 Subject: [PATCH] configurable service thread name prefix Motivation: If netty used as part of application, should be a way to prefix service thread name to easy distinguish such threads (for example, used in IntelliJ Platform) Modifications: Introduce system property io.netty.serviceThreadPrefix Result: ThreadDeathWatcher thread has a readable name "Netty threadDeathWatcher-2-1" if io.netty.serviceThreadPrefix set to "Netty" --- .../java/io/netty/util/ThreadDeathWatcher.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/io/netty/util/ThreadDeathWatcher.java b/common/src/main/java/io/netty/util/ThreadDeathWatcher.java index 2e580245f6..0804269736 100644 --- a/common/src/main/java/io/netty/util/ThreadDeathWatcher.java +++ b/common/src/main/java/io/netty/util/ThreadDeathWatcher.java @@ -19,6 +19,8 @@ package io.netty.util; import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.internal.MpscLinkedQueueNode; import io.netty.util.internal.PlatformDependent; +import io.netty.util.internal.StringUtil; +import io.netty.util.internal.SystemPropertyUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -40,14 +42,22 @@ import java.util.concurrent.atomic.AtomicBoolean; public final class ThreadDeathWatcher { private static final InternalLogger logger = InternalLoggerFactory.getInstance(ThreadDeathWatcher.class); - private static final ThreadFactory threadFactory = - new DefaultThreadFactory(ThreadDeathWatcher.class, true, Thread.MIN_PRIORITY); + private static final ThreadFactory threadFactory; private static final Queue pendingEntries = PlatformDependent.newMpscQueue(); private static final Watcher watcher = new Watcher(); private static final AtomicBoolean started = new AtomicBoolean(); private static volatile Thread watcherThread; + static { + String poolName = "threadDeathWatcher"; + String serviceThreadPrefix = SystemPropertyUtil.get("io.netty.serviceThreadPrefix"); + if (!StringUtil.isNullOrEmpty(serviceThreadPrefix)) { + poolName = serviceThreadPrefix + poolName; + } + threadFactory = new DefaultThreadFactory(poolName, true, Thread.MIN_PRIORITY); + } + /** * Schedules the specified {@code task} to run when the specified {@code thread} dies. *