Loading

线程池实现多线程

public class wrongways {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        for(int i = 0;i < 1000; i++){
                    executorService.submit(new Task(){
                    });
        }
    }
}

class Task implements Runnable{
    @Override
    public void run() {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName());//打印当前线程的名字

    }
}
posted @ 2021-12-22 21:49  Zhbeii  阅读(67)  评论(0)    收藏  举报