无边界队列:没有长度限制的队列
线程池用的是阻塞队列
1.线程池思想概述
2.线程池概念
线程池原理:
线程池概念:
3.线程池的使用
进程类:
package com.goldencis.thread.ThreadPool;
public class RunnableImpl implements Runnable {
@Override
public void run() {
System.out.println(Thread.currentThread().getName() +"执行了");
}
}
测试类:
package com.goldencis.thread.ThreadPool;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
public class Test {
public static void main(String[] args) {
//ExecutorService es = Executors.newFixedThreadPool(2);//线程池不允许使用Executors去创建,而是通过ThreadPoolExecutor的方式,这样的处理方式让写的同学更加明确线程池的运行规则,规避资源耗尽的风险。
ScheduledExecutorService es =new ScheduledThreadPoolExecutor(2);
es.submit(new RunnableImpl());
es.submit(new RunnableImpl());
es.submit(new RunnableImpl());
}
}
关于线程池的更详细内容,可以看https://www.nowcoder.com/discuss/152050?type=0&order=0&pos=6&page=0