每天中午 12 点和下午 23:00 使用 Java 和 vertx 对一个 API 执行两次调用

Execute some calls to one API twice per day at 12.00 AM and 23:00 PM with Java and vertx

我一直在玩 vertx.setTimervertx.setPeriodic 但我没有在 java 中找到一种简单的方法来执行一个计划任务(调用一个 API 在具体时间段,例如中午 12 点和下午 23 点)。 我也看过一个关于 vertx 和 chime 的博客(https://vertx.io/blog/time-scheduling-with-chime/),但我不确定它是否支持 vertx 版本 3.9.0 或是否具有一致性。 任何的想法 ? 提前谢谢你。

尝试 java.util.Timer,例如 运行 每天 21:00:

    TimerTask timerTask = new TimerTask() {
        @Override
        public void run() {
            vertx.runOnContext(event -> { System.out.println("timer in vert.x context!"); });
        }
    };

    Timer timer = new Timer();
    Calendar today = Calendar.getInstance();
    today.set(Calendar.HOUR_OF_DAY, 21);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);

    timer.schedule(timerTask, today.getTime(), TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS));