Java 线程池的使用

package com.learn.corejava.threading;



import java.util.concurrent.ExecutorService;

import java.util.concurrent.Executors;

import java.util.concurrent.ThreadPoolExecutor;



public class ThreadPoolMain {

    public static void main(String[] args) {

        ExecutorService service = Executors.newCachedThreadPool();

        for (int i = 0; i < 100; i++) {

            service.submit(() -> System.out.println(Thread.currentThread()));

        }

        service.shutdown();

    }

}

 

 

展开阅读全文