Skip to content

Commit 202b2db

Browse files
develarnormanmaurer
authored andcommitted
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"
1 parent e8e1be1 commit 202b2db

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

common/src/main/java/io/netty/util/ThreadDeathWatcher.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import io.netty.util.concurrent.DefaultThreadFactory;
2020
import io.netty.util.internal.MpscLinkedQueueNode;
2121
import io.netty.util.internal.PlatformDependent;
22+
import io.netty.util.internal.StringUtil;
23+
import io.netty.util.internal.SystemPropertyUtil;
2224
import io.netty.util.internal.logging.InternalLogger;
2325
import io.netty.util.internal.logging.InternalLoggerFactory;
2426

@@ -40,14 +42,22 @@
4042
public final class ThreadDeathWatcher {
4143

4244
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ThreadDeathWatcher.class);
43-
private static final ThreadFactory threadFactory =
44-
new DefaultThreadFactory(ThreadDeathWatcher.class, true, Thread.MIN_PRIORITY);
45+
private static final ThreadFactory threadFactory;
4546

4647
private static final Queue<Entry> pendingEntries = PlatformDependent.newMpscQueue();
4748
private static final Watcher watcher = new Watcher();
4849
private static final AtomicBoolean started = new AtomicBoolean();
4950
private static volatile Thread watcherThread;
5051

52+
static {
53+
String poolName = "threadDeathWatcher";
54+
String serviceThreadPrefix = SystemPropertyUtil.get("io.netty.serviceThreadPrefix");
55+
if (!StringUtil.isNullOrEmpty(serviceThreadPrefix)) {
56+
poolName = serviceThreadPrefix + poolName;
57+
}
58+
threadFactory = new DefaultThreadFactory(poolName, true, Thread.MIN_PRIORITY);
59+
}
60+
5161
/**
5262
* Schedules the specified {@code task} to run when the specified {@code thread} dies.
5363
*

0 commit comments

Comments
 (0)