Demo03.java 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package J20250801.homework;
  2. import java.util.concurrent.ArrayBlockingQueue;
  3. import java.util.concurrent.Executors;
  4. import java.util.concurrent.ThreadPoolExecutor;
  5. import java.util.concurrent.TimeUnit;
  6. /**
  7. * @author WanJl
  8. * @version 1.0
  9. * @title Demo01
  10. * @description
  11. * @create 2025/8/1
  12. */
  13. public class Demo03 {
  14. public static void main(String[] args) throws InterruptedException {
  15. ThreadPoolExecutor pool=new ThreadPoolExecutor(
  16. 5,
  17. 10,
  18. 60l,
  19. TimeUnit.SECONDS,
  20. new ArrayBlockingQueue<>(20),
  21. Executors.defaultThreadFactory(),
  22. new ThreadPoolExecutor.AbortPolicy());
  23. for (int i = 0; i < 100; i++) {
  24. pool.submit(()->{
  25. try {
  26. Thread.sleep(100);
  27. } catch (InterruptedException e) {
  28. e.printStackTrace();
  29. }
  30. System.out.println("处理文件[文件"+Thread.currentThread().getName()+"]完成");
  31. });
  32. }
  33. }
  34. }