Configure daemon
This commit is contained in:
parent
5030b02f49
commit
24f9811f6f
@ -39,6 +39,7 @@ public class ShortNamedThreadFactory implements ThreadFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private ThreadGroup group;
|
private ThreadGroup group;
|
||||||
|
private boolean daemon;
|
||||||
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||||
private static final String NAME_PATTERN = "%s-%d";
|
private static final String NAME_PATTERN = "%s-%d";
|
||||||
private final String threadNamePrefix;
|
private final String threadNamePrefix;
|
||||||
@ -59,6 +60,11 @@ public class ShortNamedThreadFactory implements ThreadFactory {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ShortNamedThreadFactory setDaemon(boolean daemon) {
|
||||||
|
this.daemon = daemon;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
private static String checkPrefix(String prefix) {
|
private static String checkPrefix(String prefix) {
|
||||||
return prefix == null || prefix.length() == 0 ? "Unnamed" : prefix;
|
return prefix == null || prefix.length() == 0 ? "Unnamed" : prefix;
|
||||||
}
|
}
|
||||||
@ -72,7 +78,7 @@ public class ShortNamedThreadFactory implements ThreadFactory {
|
|||||||
public Thread newThread(@NotNull Runnable r) {
|
public Thread newThread(@NotNull Runnable r) {
|
||||||
final Thread t = new Thread(group, r, String.format(Locale.ROOT, "%s-%d",
|
final Thread t = new Thread(group, r, String.format(Locale.ROOT, "%s-%d",
|
||||||
this.threadNamePrefix, threadNumber.getAndIncrement()), 0);
|
this.threadNamePrefix, threadNumber.getAndIncrement()), 0);
|
||||||
t.setDaemon(false);
|
t.setDaemon(daemon);
|
||||||
t.setPriority(Thread.NORM_PRIORITY);
|
t.setPriority(Thread.NORM_PRIORITY);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user