码迷,mamicode.com
首页 > 编程语言 > 详细

java 线程池 ---- newSingleThreadExecutor()

时间:2018-10-28 16:07:36      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:线程   color   new   int   his   ati   print   i++   cut   

 

class MyThread implements Runnable{
    private int index;

    public MyThread(int index){
        this.index = index;
    }

    @Override
    public void run() {
        System.out.println("处理任务:" + index);
    }
}
public class Test1 {
    public static void main(String[] args){

        // 创建线程池
        ExecutorService executor = Executors.newSingleThreadExecutor();

        for (int i = 0; i < 15; i++){
            MyThread myThread = new MyThread(i);
            // 任务丢进线程池
            executor.execute(myThread);
        }
        // 关闭服务
        executor.shutdown();

    }
}

 

java 线程池 ---- newSingleThreadExecutor()

标签:线程   color   new   int   his   ati   print   i++   cut   

原文地址:https://www.cnblogs.com/huanggy/p/9865629.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!