I have found that there is not need to declare an extra TaskScheduler and i can have my tasks like this:
<task:scheduled-tasks>
<task:scheduled ref="runScheduler1" method="run" cron="*/5 * * * * *" />
<task:scheduled ref="runScheduler2" method="run" cron="*/5 * * * * *" />
</task:scheduled-tasks>
But could you help me with the explanation, why it is not needed like below?
<task:scheduled-tasks>
<task:scheduled ref="runScheduler1" method="run" cron="*/5 * * * * *" />
</task:scheduled-tasks>
<task:scheduled-tasks>
<task:scheduled ref="runScheduler2" method="run" cron="*/5 * * * * *" />
</task:scheduled-tasks>
Common Schedular
This part defines one
schedulerwith two tasks in it. Both of the tasks will be executed independent of each other (as per their defined schedule). Having onescheulerwith multiple tasks in it not only groups them together but also let you control a thread-pool common for both of the tasks.The above uses one
schedulerand also tells that there are two tasks in my schedular with their own predefined fixed-delays. There is a possibility of both of the tasks and/or two occurances of a single task overlap eachother. In such cases those will be run concurrently under a thread pool of size 5.Separate Scheduler
However, in this example, there are two separate
schedulerswith one task in each. You can place differentschedulersto different context xml files (if you have multiple context xmls). You can also have separate thread pools for each of them (like in above example).As long as you dont want to have a logical separation between two tasks and you don't want to have separate thead-pools for each of them, the first approach should work for you.