定时执行线程池ScheduledExecutorService的使用

ScheduledExecutorService progressExecutorService = Executors.newScheduledThreadPool(1);
        ScheduledFuture<?> future = progressExecutorService.scheduleAtFixedRate(new Runnable() {// It begins in 0.5 seconds, and executes once every second.
            @Override
            public void run() {
                System.out.println("excel download progress:"+progress.get()+"%");
                if (progress.get() == 100) {
                    System.out.println("excel download progress is 100%");
                    progressExecutorService.shutdown();
                }
            }
        }, (long) 0.5, 1, TimeUnit.SECONDS);

 

posted @ 2018-06-09 10:03  夏威夷8080  阅读(465)  评论(0编辑  收藏  举报