我们知道,Java创建线程池的方式有四种:
具体源码如下:
import urrent.LinkedBlockingQueue;
import urrent.ThreadPoolExecutor;
import urrent.TimeUnit;public class ThreadPoolTest01 {public static void main(String[] args) {ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1,2,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(3));}
}
class TaskThread implements Runnable {private String threadName;public TaskThread(String threadName) {this.threadName = threadName;}@Overridepublic void run() {System.out.println(Thread.currentThread().getName() + this.threadName);}
}
当向线程池提交三个线程时(小于或等于4个线程):
当向线程池提交5个线程时:
当向线程池提交6个线程时(大于5个线程):
本文发布于:2024-02-01 10:52:26,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170675594836108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |