Friday, July 13, 2018

how to change shceduler times in spring

How to change scheduler times in Spring

 

Imagine that you have scheduler but you want to change time at runtime. What Can you do? Off-course there are ways do solve the problem. So In this article I will write how to implement Trigger interface that is located to the following package: org.springframework.scheduling in the spring-context project.

1. First off all, let's create interface for our logic:

























2. In Spring we have org.springframework.scheduling.Trigger interface:
























So we can write our own implementation. It's very simple. We should just overwrite nextExecutionTime(_) method.  Something like that:



3. Now we can write configuration.





In this example we just choose ThreadPoolTaskScheduler that is child ofTaskScheduler interface.


4. So what is the next? Let's see how to use our scheduler. Everything is simple:



That's it!

Goodbye!
Have good day!

No comments:

Post a Comment