标签:fixed ble sch 面试 容量 哪些 lex argument eject
面试官:线程池有哪些?分别的作用是什么?
常用的线程池有:
1、newSingleThreadExecutor:
单个线程的线程池,即线程池中每次只有一个线程工作,单线程串行执行任务;
2、newFixedThreadExecutor:
固定数量的线程池,每提交一个任务就是一个线程,直到线程达到线程池的最大数量,然后后面进入等待队列直到前面的任务才继续执行;
3、newCacheThreadExecutor:
可缓存线程池,当线程池大小超过了处理任务所需的线程,那么就会回收部分空闲(一般 是60秒无执行)的线程,当有任务时,会添加新线程来执行;
4、newScheduleThreadExecutor:
大小无限制的 线程池,支持定时和周期性的执行线程。
ThreadPoolExecutor解说:
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; }
标签:fixed ble sch 面试 容量 哪些 lex argument eject
原文地址:https://www.cnblogs.com/hujinshui/p/9961225.html