package J20250731.demo03_threadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author WanJl
 * @version 1.0
 * @title ThreadPoolDemo01
 * @description
 * @create 2025/7/31
 */
public class ThreadPoolDemo01 {
    public static void main(String[] args) {
        //1、创建一个默认的线程池对象
        ExecutorService executorService = Executors.newCachedThreadPool();
        //Executors 帮我们创建一个线程池对象
        //ExecutorService 可以帮我们控制线程池对象

        //如果有任务想要交给线程执行，我们只需要调用executorService的submit方法，把任务传进去
        for (int i = 0; i < 10; i++) {
            executorService.submit(()->{
                System.out.println("线程id："+Thread.currentThread().getId()+",线程名："+Thread.currentThread().getName()+"在执行了.....");
            });
        }

        //关闭线程池
        executorService.shutdown();

    }
}
