您好,欢迎来到刀刀网。
搜索
您的当前位置:首页Java自带线程池

Java自带线程池

来源:刀刀网


package thread;

import org.junit.Test;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by guofeipeng on 15/11/17.
 * 线程池测试
 */
public class TestThreadPool {

    @Test
    public void testThradPool(){
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(30, 50,  60L, TimeUnit.SECONDS,
                new SynchronousQueue<Runnable>());
        for(int i = 0 ; i < 10 ; i++){
            Thread t = new Thread(new Task());
            t.setName("thread" + i);
            threadPoolExecutor.execute(t);
        }
        threadPoolExecutor.shutdown();
        while (!threadPoolExecutor.isTerminated()) {

        }
    }


    class Task implements Runnable{
        @Override
        public void run() {
            System.out.println("task " + Thread.currentThread().getName());
        }
    }
}







因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- gamedaodao.com 版权所有 湘ICP备2022005869号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务