如何使用数据库数据动态添加或删除 spring 框架的调度程序(服务器处于 运行 状态)?

How to ADD OR REMOVE spring framework's scheduler dynamically(server in running status) with DB data?

我正在与 Spring-boot 和 Oracle sql 开发人员一起工作。 我想实现类似 'user administrating scheduler'.

的东西

用户可以在网页上添加或删除调度程序。 如果用户添加 'scheduler running every 3 minutes',db table 可能是...

s_id | s_cron | s_detail
sid000001 | 0 0/3 * * * ? | do job 1

和 spring 调度程序必须每 3 分钟执行 'job 1'。

如果,另一个用户也添加 'scheduler running every 1 minutes',

s_id | s_cron | s_detail
sid000001 | 0 0/3 * * * ? | do job 1
sid000002 | 0 0/1 * * * ? | do job 2

和 spring 调度程序必须每 3 分钟执行一次 'job 1',并且必须同时每 1 分钟执行一次 'job 2'。

问题是:如何在 Spring-boot 中设置它? Spring 服务必须 add/remove 在服务器 运行.

中使用数据库数据 added/removed 动态(或自动)调度程序

请帮帮我。

如果你想动态安排任务,你可以在没有 spring 的情况下使用 ExecutorService,特别是 ScheduledThreadPoolExecutor

Runnable task  = () -> doSomething();
ScheduledExecutorService executor = 
Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
// Schedule a task that will be executed in 120 sec
executor.schedule(task, 120, TimeUnit.SECONDS);

// Schedule a task that will be first run in 120 sec and each 120sec
// If an exception occurs then it's task executions are canceled.
executor.scheduleAtFixedRate(task, 120, 120, TimeUnit.SECONDS);

// Schedule a task that will be first run in 120 sec and each 120sec after 
the last 
execution
// If an exception occurs then it's task executions are canceled.
executor.scheduleWithFixedDelay(task, 120, 120, TimeUnit.SECONDS);