线程池

本文详细解析了线程池核心类ThreadPoolExecutor的构造方法,包括核心线程数、最大线程数、线程空闲时间等关键参数的设置及作用。同时介绍了线程工厂、任务队列、拒绝策略等组件的工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 public ThreadPoolExecutor(int corePoolSize,
                              int maximumPoolSize,
                              long keepAliveTime,
                              TimeUnit unit,
                              BlockingQueue<Runnable> workQueue,
                              ThreadFactory threadFactory,
                              RejectedExecutionHandler handler) {
        if (corePoolSize < 0 ||
            maximumPoolSize <= 0 ||
            maximumPoolSize < corePoolSize ||
            keepAliveTime < 0)
            throw new IllegalArgumentException();
        if (workQueue == null || threadFactory == null || handler == null)
            throw new NullPointerException();
        this.acc = System.getSecurityManager() == null ?
                null :
                AccessController.getContext();
        this.corePoolSize = corePoolSize;
        this.maximumPoolSize = maximumPoolSize;
        this.workQueue = workQueue;
        this.keepAliveTime = unit.toNanos(keepAliveTime);
        this.threadFactory = threadFactory;
        this.handler = handler;
    }

上面就是线程池源码核心类
ThreadPoolExecutor
参数解读

  1. int corePoolSize 核心线程数大小,
  2. int maximumPoolSize, 线程池总大小
  3. long keepAliveTime, 线程空闲后保持时间
  4. TimeUnit unit, 时间维度,秒,分,小时
  5. BlockingQueue workQueue, 任务缓存的阻塞队列
  6. ThreadFactory threadFactory, 创建线程的工程类
  7. RejectedExecutionHandler handler 抛弃策略当线程放不下的时候,如何处理
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值