定时器 ScheduledExecutorService

mac2022-06-30  82

 

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时间单位); } }

 

转载于:https://www.cnblogs.com/mryangbo/p/11258735.html

相关资源:自定义Java-ScheduledExecutorService定时器.jar
最新回复(0)