SpringWeb项目启动后,执行一个方法,并且只执行一次
作者:互联网
ScheduledExecutorService.schedule 方法
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(5); scheduledThreadPool.schedule(new Runnable() { @Override public void run() { System.out.println("delay 3 seconds"); } }, 3, TimeUnit.SECONDS);
表示延迟3秒执行,并且只执行一次。
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(5); scheduledThreadPool.scheduleAtFixedRate(new Runnable() { @Override public void run() { System.out.println("delay 1 seconds, and excute every 3 seconds"); } }, 1, 3, TimeUnit.SECONDS);
表示延迟1秒后每3秒执行一次。
标签:启动,seconds,SpringWeb,System,Override,ScheduledExecutorService,scheduledThreadPoo 来源: https://www.cnblogs.com/acm-bingzi/p/spring_delay.html