指定时间执行任务
作者:
养一只tom猫 | 来源:发表于
2021-03-24 11:29 被阅读0次private static ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(4);
public static void main(String[] args) {
Runnable runnable = new Runnable() {
@Override
public void run() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("执行时间:" + sdf.format(new Date()));
}
};
Date date = new Date(System.currentTimeMillis() + 6000L);
scheduledExecutor.schedule(runnable, date.getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
}
本文标题:指定时间执行任务
本文链接:https://www.haomeiwen.com/subject/ingchltx.html
网友评论