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"
This commit is contained in:
Vladimir Krivosheev 2015-10-30 10:59:33 +01:00 committed by Norman Maurer
parent 98eb69f169
commit a4f3e72e71

View File

@ -19,6 +19,8 @@ package io.netty.util;
import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.internal.MpscLinkedQueueNode; import io.netty.util.internal.MpscLinkedQueueNode;
import io.netty.util.internal.PlatformDependent; 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.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -40,14 +42,22 @@ import java.util.concurrent.atomic.AtomicBoolean;
public final class ThreadDeathWatcher { public final class ThreadDeathWatcher {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ThreadDeathWatcher.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(ThreadDeathWatcher.class);
private static final ThreadFactory threadFactory = private static final ThreadFactory threadFactory;
new DefaultThreadFactory(ThreadDeathWatcher.class, true, Thread.MIN_PRIORITY);
private static final Queue<Entry> pendingEntries = PlatformDependent.newMpscQueue(); private static final Queue<Entry> pendingEntries = PlatformDependent.newMpscQueue();
private static final Watcher watcher = new Watcher(); private static final Watcher watcher = new Watcher();
private static final AtomicBoolean started = new AtomicBoolean(); private static final AtomicBoolean started = new AtomicBoolean();
private static volatile Thread watcherThread; 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. * Schedules the specified {@code task} to run when the specified {@code thread} dies.
* *