ScheduledExecutorService每晚12点UTC时间执行

时间:2017-04-21 07:42:00

标签: java datetime runnable scheduledexecutorservice

我想每天正好上午12点启动ScheduledExecutorService,Schedule必须在今天22/02/2017 00:00:00(UTC TIME)开始,任何人都能告诉我我的代码是否正确吗?

DateTime today = new DateTime().withTimeAtStartOfDay(); 
        DateTime startOfTommorrow = today.plusDays(1).withTimeAtStartOfDay();

        Long midnight = startOfTommorrow.getMillis();
        long midnights = (midnight / 1000)  / 60;
        final DateFormat nextDateTymFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        System.out.println("***********************************");
        System.out.println("Schedule Updater "+nextDateTymFormat.format(new Date()));
        System.out.println("today "+today);
        System.out.println("startOfTommorrow "+startOfTommorrow);
        System.out.println("midnight Long "+midnight);
        System.out.println("***********************************");
        vitalScheduleThread.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {

                System.out.println("Hello vitalSchService !!"+nextDateTymFormat.format(new Date()));

                Thread.currentThread().setName("vitalSchService");

                //sendMail();
                vitalSchedule.process(springContext);
            }
        }, midnight , 86400000 , TimeUnit.MILLISECONDS

);

0 个答案:

没有答案