java中常用线程池:newScheduledThreadPool

2025-05-18 10:39:09

1、通过Executors创建线程池newSchedule蟠校盯昂dThreadPool的实例。同newFixedThreadPool线程池类型一样,设置并发数最大值。注意该出ScheduledExecutorService继承了ExecutorService。

java中常用线程池:newScheduledThreadPool

3、在线程run方法中随意输出一段话,用于模拟线程定时运行。

java中常用线程池:newScheduledThreadPool

5、newScheduledThreadPool用于周期执行时,可以使用方法scheduleAtFixedRate。如下代码中即是延迟2s中每隔5秒运行一次。

java中常用线程池:newScheduledThreadPool
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢