1. 程式人生 > >定時執行線程池ScheduledExecutorService的使用

定時執行線程池ScheduledExecutorService的使用

con down over progress ever .get system print 線程

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);

定時執行線程池ScheduledExecutorService的使用