![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java多线程
文章平均质量分 59
睡到天荒地老
这个作者很懒,什么都没留下…
展开
-
创建线程-四种方式
创建线程目前共四种方式:继承Thread类 、实现Runable接口、实现Callable接口、由线程池创建继承Thread类并重写run方法:run()方法为线程具体执行内容public class ThreadDemo { public static void main(String[] args) { Thread thread01 = new MyThread(); Thread thread02 = new MyThre原创 2021-06-30 16:27:07 · 168 阅读 · 0 评论 -
创建线程池
一、Executors创建(1)通用线程池:newCachedThreadPool();ExecutorService cachedThreadPool = Executors.newCachedThreadPool();1.线程数无限制2.有空闲线程则复用空闲线程,若无空闲线程则新建线程3.一定程度减少频繁创建/销毁线程,减少系统开销(2)定长线程池:newFixedThreadPool(int corePoolSize);ExecutorService fixedTh原创 2021-06-30 15:04:00 · 436 阅读 · 1 评论