指定时间执行任务

2021-03-24  本文已影响0人  养一只tom猫
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);
    }
上一篇 下一篇

猜你喜欢

热点阅读