线程池

package 多线程练习;

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

public class 线程池 {
    public static void main(String[] args) {
        Runnable rb =()->{
            System.out.println(Thread.currentThread().getName());
        };

        // 创建线程池
        ExecutorService service =  Executors.newFixedThreadPool(10);

        // 调用  execute是执行thread跟runnable 无返回值   submit是调用callable有返回值的
        service.execute(rb);
        service.execute(rb);
        service.execute(rb);
        service.execute(rb);
        service.execute(rb);
        service.execute(rb);
        service.execute(rb);


        service.shutdown();

    }
}

 

 

输出结果

 

posted @ 2022-01-16 17:06  Chris丶Woo  阅读(14)  评论(0编辑  收藏  举报