简体   繁体   中英

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. You can schedule jobs using user input and have better control over task execution.

Declare you scheduler in spring context:

<task:scheduler id="taskScheduler" pool-size="5" />

And inject it into your service beans using @Autowire annotation

@Autowire
private TaskScheduler taskScheduler;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM