Maven config
1 | <dependencies> |
Add @EnableScheduling
annotation in application main or configuration class
Thread pool
In org.springframework.scheduling.config.ScheduledTaskRegistrar
after the after properties set, spring set a default single thread excutor.
1 | protected void scheduleTasks() { |
When the program’s schedules need time to deal with the job.
Single Thread excutor may cause job be blocked, then the job’s excuted time might be wrong.
So when the single node have hard works need be done precisely, we need a selfdefine threadpool.
1 |
|
Close
When the web application closed, the threadpool is still alive, we need actively close it.
1 | @Component |
Cluster
If the schedule needs enterprise level structure, a schedule cluster is needed.
Use consistency middle ware/[DB]/[Cache] control the schedule node’s behaviour.
Use Message queue control the job’s status/ corn, even add/ remove jobs.
Spring schedule not support the persistency feature, but through mechanism it still can be resolved.
If the requirement is that level, use spring schedule may not be a good choice.
https://www.cnblogs.com/skychenjiajun/p/9057379.html
https://blog.csdn.net/qq_34125349/article/details/77430956