A user wants to start or stop tasks via a user interface. The tasks are stored in a database in case a restart is needed.
When investigating a few alternatives, I came across a solution with ScheduledTaskRegistrar.
My question is: how can I stop any started job in a ScheduledTaskRegistrar context?
Using Quartz is another solution, but I would prefer a lightweight, simple solution.
Is there a better simple framework or is Quartz the right way to go?
When investigating some existing packages and especially Quartz, Quartz was not appropriate in this case. We needed here a lightweight solution. In other cases we used it.
Inspired by a number of posts and articles I devised the following simple but effective package. It works well for scheduling tasks with cron expressions. It could easily be enhanced with other triggers. After restarting the app (or a crash) the tasks are automatically rescheduled again.
I hope you also benefit from it.
The config:
The TaskDefinition:
A sample service. Working with prototype beans would of course be better, but in my case this is good enough. You can easily enhance this.
The scheduling service, based on the above config class:
Play time: putting it all behind an API so you can create a demo yourself with eg. Postman:
And a POJO for a task request:
Enjoy!