自己封装一个类
代码如下 | 复制代码 |
package com.anllin.utils; import java.text.DateFormat; public class ScheduleUtil private static Date parseTime(String time) throws ParseException private static long getOneDayMilliseconds() private static long getMillisecondsInOneDayBetween(String now, String future) throws ParseException public static void scheduleEveryday(ScheduledThreadPoolExecutor executor, Runnable command, |
调用方法
代码如下 | 复制代码 |
public static void main(String[] args) throws Exception { ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(5); String executedEverydayAt = "12:00:00:000"; ScheduleUtil.scheduleEveryday(executor, new Runnable(){ public void run() { System.out.println("执行业务逻辑"); } }, executedEverydayAt); } |