java线程池ThreadPool

 1 package com.java.concurrent;
 2 
 3 import java.util.concurrent.ExecutorService;
 4 import java.util.concurrent.Executors;
 5 
 6 public class TestThreadPool {
 7     public static void main(String[] args) {
 8         //1.创建线程池
 9         ExecutorService pool =  Executors.newFixedThreadPool(5);
10         ThreadPoolDemo d = new ThreadPoolDemo();
11         for(int i=0;i<1000;i++){
12             pool.submit(d);
13             }
14         pool.shutdown();
15     }
16     
17     }
18 
19 
20 class ThreadPoolDemo implements Runnable{
21     int i=1000;
22     int j=0;
23     public void run() {
24         j++;
25         System.out.println("当前输出+"+j+""+i--);
26     }
27     
28     
29     
30     
31 }

 欢迎大家加入java资源免费分享群,群号:814657026

posted @ 2017-10-17 13:18  fliay  阅读(178)  评论(0编辑  收藏  举报