123456789101112131415161718192021222324252627282930313233343536373839 |
- package J20250801.homework;
- import java.util.concurrent.ArrayBlockingQueue;
- import java.util.concurrent.Executors;
- import java.util.concurrent.ThreadPoolExecutor;
- import java.util.concurrent.TimeUnit;
- /**
- * @author WanJl
- * @version 1.0
- * @title Demo01
- * @description
- * @create 2025/8/1
- */
- public class Demo03 {
- public static void main(String[] args) throws InterruptedException {
- ThreadPoolExecutor pool=new ThreadPoolExecutor(
- 5,
- 10,
- 60l,
- TimeUnit.SECONDS,
- new ArrayBlockingQueue<>(20),
- Executors.defaultThreadFactory(),
- new ThreadPoolExecutor.AbortPolicy());
- for (int i = 0; i < 100; i++) {
- pool.submit(()->{
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println("处理文件[文件"+Thread.currentThread().getName()+"]完成");
- });
- }
- }
- }
|