public class ScheduledExecutorServiceDemo { public static void main(String[] args) { ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10); scheduledExecutorService.scheduleAtFixedRate(new Runnable() { public void run() { try { Thread.sleep(8000);//模拟执行任务时间 System.out.println(System.currentTimeMillis()/1000); } catch (InterruptedException e) { e.printStackTrace(); } } },0,2, TimeUnit.SECONDS); //执行周期为2秒,由于执行任务时间为8秒,执行之后立即执行下个周期 } }执行时间为:1515598131,1515598139,1515598147
ScheduledExecutorService
最新推荐文章于 2024-05-14 14:04:24 发布