pass on thread pool executor name to thread factory and from there to threads

Change-Id: I0748fc2da7965ee33bebb73e4f2aaecd463963f0
This commit is contained in:
Axel Uhl committed 2017-05-30 23:20:39 +02:00
1 parent 50aedb4977
commit cc92218656
3 files changed
+22 -4

No files matched your search

@@ -14,6 +14,7 @@ public class ThreadFactoryWithPriority implements ThreadFactory {
private ThreadFactory defaultFactory;
private final int priority;
private final Boolean daemon;
private final String name;
/**
* @param daemon
@@ -22,7 +23,22 @@ public class ThreadFactoryWithPriority implements ThreadFactory {
* threads created by this factory shall be daemon threads.
*/
public ThreadFactoryWithPriority(int priority, Boolean daemon) {
this(/* name */ null, priority, daemon);
}
/**
* @param name
* provides an optional name prefix for the threads to be created; the default thread name is provided by
* the default thread factory by using a prefix of the kind "pool-x-thread-y". If not {@code null}, the
* {@code name} is prepended to this name.
* @param daemon
* if <code>null</code>, the threads produced by this factory will be daemon threads if and only if the
* caller of {@link #newThread} runs in a daemon thread; otherwise, this parameter determines whether the
* threads created by this factory shall be daemon threads.
*/
public ThreadFactoryWithPriority(String name, int priority, Boolean daemon) {
defaultFactory = Executors.defaultThreadFactory();
this.name = name;
this.priority = priority;
this.daemon = daemon;
}
@@ -34,8 +50,9 @@ public class ThreadFactoryWithPriority implements ThreadFactory {
if (daemon != null) {
result.setDaemon(daemon);
}
if (name != null) {
result.setName(name+" "+result.getName());
}
return result;
}
}
@@ -45,7 +45,8 @@ public class ThreadPoolUtilImpl implements ThreadPoolUtil {
}
private ScheduledExecutorService createThreadPoolExecutor(String name, final int priority, final int size) {
return new NamedTracingScheduledThreadPoolExecutor(name, /* corePoolSize */ size, new ThreadFactoryWithPriority(priority, /* daemon */ true));
return new NamedTracingScheduledThreadPoolExecutor(name, /* corePoolSize */ size, new ThreadFactoryWithPriority(
name, priority, /* daemon */ true));
}
@Override