- 可由一个定时器进行一次或多次执行的任务。
- scheduledExecutionTime方法返回任务最近执行的时间
- cancel方法是停止任务执行
public static void main(String[] args) { timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { GGLogger.info("定时任务清空用户缓存信息数量为=========>>"+CacheUtil.size()); CacheUtil.clear(); System.out.println(DateFormatUtils.format(this.scheduledExecutionTime(), "yyyy-MM-dd HH:mm:ss")); this.cancel(); } }; timer.schedule(task, 0, 2*1000); }