首页 > 其他 > 详细

定时器 ScheduledExecutorService

时间:2019-07-28 15:28:11      阅读:46      评论:0      收藏:0      [点我收藏+]

 

public class ScheduleTest {
    private static int a=0;
        public static void main(String[] args) throws InterruptedException {
            ScheduledExecutorService execService =   Executors.newSingleThreadScheduledExecutor();
            execService.scheduleWithFixedDelay(new Runnable() {
                @Override
                public void run() {
                    System.out.println(a++);
                    if(a==5){
                        execService.shutdown();
                    }
                }
            }, 0, 1, TimeUnit.SECONDS);
            //(Runnable command线程代码,long initialDelay多长时间后运行任务,long delay任务结束后多长时间开始任务,TimeUnit unit时间单位);
        }
}

 

定时器 ScheduledExecutorService

原文:https://www.cnblogs.com/mryangbo/p/11258735.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!