美文网首页
指定时间执行任务

指定时间执行任务

作者: 养一只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