ScheduledThreadPoolExecutor api解析

本文通过单元测试详细探索ScheduledThreadPoolExecutor的公共API,涵盖了Java并发编程中的重要工具类。虽然初次接触,但已能理解其基本用法,部分细节仍有待进一步研究和完善。
摘要由CSDN通过智能技术生成

今天时间学习ScheduledThreadPoolExecutor  api,该类是JUC原子包中的类,通过单元测试代码把所有public api方法跑了一遍,大致了解了底层实现,初学乍练,有很多一知半解的地方,待后续有了深入理解再来补充

 

package test.java.util.concurrent;


import java.util.concurrent.*;

import org.junit.Test;

/**
 * ScheduledThreadPoolExecutor的测试类
 *
 * @date 2020-07-27 22:40:10
 */
public class ScheduledThreadPoolExecutorTest {
        /**
        * 使用指定参数初始化线程池大小,其他默认
        * @Param
        */
        @Test
        public void testConstruct0()throws Exception{
        ScheduledThreadPoolExecutor testObj=new ScheduledThreadPoolExecutor(3);
                testObj.submit(()-> System.out.println(111));
        }
        /**
        *使用指定参数初始化线程池大小,使用指定线程工厂,其他默认
        * @Param
        */
        @Test
        public void testConstruct1()throws Exception{
        ScheduledThreadPoolExecutor testObj=new ScheduledThreadPoolExecutor(3, Executors.defaultThreadFactory());
                testObj.submit(()-> System.out.println(111));
        }
        /**
        * 使用指定参数初始化线程池大小,使用指定拒绝策略
        * @Param
        */
        @Test
        public void testConstruct2()throws Exception{
        ScheduledThreadPoolExecutor testObj=new ScheduledThreadPoolExecutor(3,new ThreadPoolExecutor.CallerRunsPolicy());
                testObj.submit(()-> System.out.println(111));
        }
        /**
        *使用指定参数初始化线程池大小,使用指定线程工厂,使用指定拒绝策略
        * @Param
        */
        @Test
        public void testConstruct3()throws Exception{
        ScheduledThreadPoolExecutor testObj=new ScheduledThreadPoolExecutor(3,Executors.defaultThreadFactory(),new ThreadPoolExecutor.CallerRunsPolicy());
                testObj.submit(()-> System.out.println(111));
        }
        /**
         * 延迟多长时间执行
         * @Param
         */
        @Test
        public void testSchedule()throws Exception{
                ScheduledThreadPoolExecutor testObj=new ScheduledThreadPoolExecutor(3,Executors.defaultThreadFactory(),new
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值