【问题标题】:How to execute cron distributed task in hazelcast IScheduledExecutorService?如何在 hazelcast IScheduledExecutorService 中执行 cron 分布式任务?
【发布时间】:2020-10-22 16:57:56
【问题描述】:

我有 hazelcast 集群,我目前正在我的项目中使用 Spring 的 TaskScheduler 来执行 cron 任务。

我想使用 hazelcast IScheduledExecutorService 为所有成员安排一个 cron 任务,并安排多个 cron 任务将在集群中平均分配,但我找不到合适的方法。

我在 IScheduledExecutorService 中找不到参数中有 cron 触发器的方法,只有 timeUnit。你知道有什么解决办法吗?

【问题讨论】:

    标签: cron scheduled-tasks hazelcast distributed taskscheduler


    【解决方案1】:

    IScheduledExecutorService 不是一个完整的 cron 调度程序,因为它只允许调度单个未来执行和/或固定速率执行,但不能在固定时间、日期或间隔定期执行。因此,如果您乐于执行以下操作:

    executorService.schedule(new SomeTask(), 10, TimeUnit.SECONDS)
    

    SomeTask 将在 10 秒后运行,然后您可以选择以下任何 API 来提交您的任务:

    scheduleOnMember:在特定集群成员上。 scheduleOnKeyOwner:在拥有该密钥的分区上。 scheduleOnAllMembers:在所有集群成员上。 scheduleOnAllMembers:在所有给定成员上。

    查看参考手册了解详情:https://docs.hazelcast.org/docs/4.0.1/manual/html-single/index.html#scheduled-executor-service

    【讨论】:

    • 感谢您的回答,您是否知道 IScheduledExecutorService 的替代方案可以接受 cron 并允许跨 hazelcast 成员进行分布式任务调度?
    猜你喜欢
    • 1970-01-01
    • 2013-11-09
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多