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);
}
网友评论