java qtp开头的线程的哪来的,是哪个线程池的

日志中很多线程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;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值