125.线程池-ThreadPoolExecutor__

本文详细介绍了Java中ThreadPoolExecutor的核心参数设置,如核心线程数、最大线程数、空闲线程存活时间等,并通过示例展示了如何创建和使用ThreadPoolExecutor。同时探讨了线程工厂和任务拒绝策略的重要性。
package com.itheima.MythoeadPool;

import java.util.concurrent.*;

public class MyThreadPooDemo3 {
    //1.核心线程数量
    //2.最大线程数
    //3.空闲线程最大存活时间
    //4.时间单位
    //5.认为队列
    //6.创建线程工厂
    //7.任务的拒绝策略
    public static void main(String[] args) {

        ThreadPoolExecutor pool=new ThreadPoolExecutor(2,5,2, TimeUnit.SECONDS,new ArrayBlockingQueue<>(10),Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        pool.submit(new MyRunnable());
        pool.submit(new MyRunnable());

        pool.shutdown();

    }
}
package com.itheima.MythoeadPool;

public class MyRunnable implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"在执行了");
    }
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值