编程语言
首页 > 编程语言> > java多线程-线程池

java多线程-线程池

作者:互联网

 如何创建线程池? 

有五种:

 

 

ThreadPoolExecutor的构造函数:

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.corePoolSize = corePoolSize;
        this.maximumPoolSize = maximumPoolSize;
        this.workQueue = workQueue;
        this.keepAliveTime = unit.toNanos(keepAliveTime);
        this.threadFactory = threadFactory;
        this.handler = handler;
    }

为什么使用线程池?

 

线程池的状态:五种

 

 

线程池的大小如何选定? 

标签:销毁,java,corePoolSize,keepAliveTime,handler,线程,多线程,CPU
来源: https://www.cnblogs.com/starstarstar/p/11240972.html