[英]Running a job/asynchronous task with spring 3 at frequency that can be altered by the user
I can set a task to run using scheduled annotation with a fixed frequency. 我可以将任务设置为使用固定频率的预定注释运行。 However I want the frequency to vary depending on user input.
但是我希望频率根据用户输入而变化。
What is the best way to accomplish this ? 完成此任务的最佳方法是什么?
I suggest using TaskScheduler directly without @Scheduled annotations. 我建议直接使用TaskScheduler而不使用@Scheduled注释。 You can schedule jobs using user input and have better control over task execution.
您可以使用用户输入来调度作业,并可以更好地控制任务执行。
Declare you scheduler in spring context: 在spring上下文中声明调度程序:
<task:scheduler id="taskScheduler" pool-size="5" />
And inject it into your service beans using @Autowire annotation 并使用@Autowire注释将其注入服务bean
@Autowire
private TaskScheduler taskScheduler;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.