日志中很多线程id,有的是线程池自定义的名称,还有很多qtp开头的,不知道他们是哪来的
今天跟Jetty代码,才看到,这些是是Jetty的worker线程池QueuedThreadPool的
org.eclipse.jetty.util.thread.QueuedThreadPool
如下:
<init>:133, Server (org.eclipse.jetty.server)
createServer:982, JettyEmbeddedServletContainerFactory$Jetty9ServerFactory (org.springframework.boot.context.embedded.jetty)
createServer:197, JettyEmbeddedServletContainerFactory (org.springframework.boot.context.embedded.jetty)
getEmbeddedServletContainer:174, JettyEmbeddedServletContainerFactory (org.springframework.boot.context.embedded.jetty)
createEmbeddedServletContainer:166, EmbeddedWebApplicationContext (org.springframework.boot.context.embedded)
onRefresh:136, EmbeddedWebApplicationContext (org.springframework.boot.context.embedded)
refresh:537, AbstractApplicationContext (org.springframework.context.support)
refresh:124, EmbeddedWebApplicationContext (org.springframework.boot.context.embedded)
refresh:693, SpringApplication (org.springframework.boot)
refreshContext:360, SpringApplication (org.springframework.boot)
run:303, SpringApplication (org.springframework.boot)
run:1118, SpringApplication (org.springframework.boot)
run:1107, SpringApplication (org.springframework.boot)
main:49, DossierApplication (com.thunisoft.dzjz.server)
此处的getThreadPool()返回为空,如果想自定义线程池,可以调用在Jetty启动前创建线程池并调用setThreadPool方法
org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory
private Server createServer(InetSocketAddress address) {
Server server;
if (ClassUtils.hasConstructor(Server.class, ThreadPool.class)) {
server = new Jetty9ServerFactory().createServer(getThreadPool());
}
else {
server = new Jetty8ServerFactory().createServer(getThreadPool());
}
server.setConnectors(new Connector[] { createConnector(address, server) });
return server;
}
/**
* Returns a Jetty {@link ThreadPool} that should be used by the {@link Server}.
* @return a Jetty {@link ThreadPool} or {@code null}
*/
public ThreadPool getThreadPool() {
return this.threadPool;
}
/**
* Set a Jetty {@link ThreadPool} that should be used by the {@link Server}. If set to
* {@code null} (default), the {@link Server} creates a {@link ThreadPool} implicitly.
* @param threadPool a Jetty ThreadPool to be used
*/
public void setThreadPool(ThreadPool threadPool) {
this.threadPool = threadPool;
}
当传入的pool为空,创建默认线程池QueuedThreadPool
org.eclipse.jetty.server.Server
public Server(@Name("threadpool") ThreadPool pool)
{
_threadPool=pool!=null?pool:new QueuedThreadPool();
addBean(_threadPool);
setServer(this);
}
可以看到,是”qtp” + hashCode()+ “-” + thread.getId()
@ManagedObject("A thread pool")
public class QueuedThreadPool extends ContainerLifeCycle implements SizedThreadPool, Dumpable, TryExecutor
{
private static final Logger LOG = Log.getLogger(QueuedThreadPool.class);
private final AtomicInteger _threadsStarted = new AtomicInteger();
private final AtomicInteger _threadsIdle = new AtomicInteger();
private final AtomicLong _lastShrink = new AtomicLong();
private final Set<Thread> _threads = ConcurrentHashMap.newKeySet();
private final Object _joinLock = new Object();
private final BlockingQueue<Runnable> _jobs;
private final ThreadGroup _threadGroup;
private String _name = "qtp" + hashCode();
private int _idleTimeout;
private int _maxThreads;
private int _minThreads;
private int _reservedThreads = -1;
private TryExecutor _tryExecutor = TryExecutor.NO_TRY;
private int _priority = Thread.NORM_PRIORITY;
private boolean _daemon = false;
private boolean _detailedDump = false;
private int _lowThreadsThreshold = 1;
private ThreadPoolBudget _budget;
public QueuedThreadPool()
{
this(200);
}
*****
private boolean startThreads(int threadsToStart)
{
while (threadsToStart > 0 && isRunning())
{
int threads = _threadsStarted.get();
if (threads >= _maxThreads)
return false;
if (!_threadsStarted.compareAndSet(threads, threads + 1))
continue;
boolean started = false;
try
{
Thread thread = newThread(_runnable);
thread.setDaemon(isDaemon());
thread.setPriority(getThreadsPriority());
thread.setName(_name + "-" + thread.getId());
_threads.add(thread);
_lastShrink.set(System.nanoTime());
thread.start();
started = true;
--threadsToStart;
}
finally
{
if (!started)
_threadsStarted.decrementAndGet();
}
}
return true;
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/93687.html