Java线程池为何保持线程一直存在
Posted mitsuhide1992
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java线程池为何保持线程一直存在相关的知识,希望对你有一定的参考价值。
java.util.concurrent.Executors:
static class DefaultThreadFactory implements ThreadFactory
private static final AtomicInteger poolNumber = new AtomicInteger(1);
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
DefaultThreadFactory()
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
namePrefix = "pool-" +
poolNumber.getAndIncrement() +
"-thread-";
public Thread newThread(Runnable r)
Thread t = new Thread(group, r,
namePrefix + threadNumber.getAndIncrement(),
0);
if (t.isDaemon())
t.setDaemon(false);
if (t.getPriority() != Thread.NORM_PRIORITY)
t.setPriority(Thread.NORM_PRIORITY);
return t;
守护线程:
http://www.cnblogs.com/luochengor/archive/2011/08/11/2134818.html
以上是关于Java线程池为何保持线程一直存在的主要内容,如果未能解决你的问题,请参考以下文章
Java Review - 创建线程和线程池时建议指定与业务相关的名称