简体   繁体   English

使用弹簧3以可由用户更改的频率运行作业/异步任务

[英]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.

相关问题 如何在春季获取当前正在运行的计划任务/作业列表? - How to get list of current running scheduled task / job in spring? 如何使用spring触发异步批处理任务? - How can I use spring to fire off an asynchronous batch task? 如何改善运行异步任务 - How to improve running asynchronous task 在异步任务之后运行代码 - Running the code after an asynchronous task 黑客可以更改模型属性吗? 春天,Java - can model attributes be altered by a hacker? Spring, Java Spark作业返回后不久,投机任务是否可以继续运行? - Can a speculative task continue running shortly after a Spark job returned? JAVA Web应用程序异步推送通知,让用户知道长时间运行的作业的状态 - JAVA web application Asynchronous push notification to let user know status of long running job 如何查找先前未在Spring Batch中运行的任何先前运行的作业/任务? 我尝试了一些代码,但不确定 - How to find any of previously running job/task is not running in spring batch? I hv tried some code but not sure Java Spring调度程序中的异步任务 - Asynchronous task within scheduler in Java Spring 如何在另一个作业中进行异步Spring Batch作业 - How to make an asynchronous spring batch job with in another job
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM