• Now all data be ready for publish, We had made our blog alive now. Haha.

  • These days CCP GFW blocked all the IPs from US and when I switch my IP in google Cloud, the disk data cannot be restore again. I have to restart my blog totally, Now the website is still building…

Scheduling a job with Spring programmatically (with fixedRate set dynamically)- Stack Overflow

Java PingBook 1 months ago (10-23) 17 0


Currently I have this :

public void getSchedule(){
System.out.println(“in scheduled job”);

I could change this to use a reference to a property

public void getSchedule(){
System.out.println(“in scheduled job”);

However I need to use a value obtained programmatically so the schedule can be changed without redeploying the app. What is the best way? I realize using annotations may not be possible…


Using a Trigger you can calculate the next execution time on the fly.

Something like this should do the trick (adapted from the Javadoc for @EnableScheduling):

public class MyAppConfig implements SchedulingConfigurer {

Environment env;

public MyBean myBean() {
return new MyBean();

@Bean(destroyMethod = “shutdown”)
public Executor taskExecutor() {
return Executors.newScheduledThreadPool(100);

public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
new Runnable() {
@Override public void run() {
new Trigger() {
@Override public Date nextExecutionTime(TriggerContext triggerContext) {
Calendar nextExecutionTime = new GregorianCalendar();
Date lastActualExecutionTime = triggerContext.lastActualExecutionTime();
nextExecutionTime.setTime(lastActualExecutionTime != null ? lastActualExecutionTime : new Date());
nextExecutionTime.add(Calendar.MILLISECOND, env.getProperty(“myRate”, Integer.class)); //you can get the value from wherever you want
return nextExecutionTime.getTime();

Copyright from PingBook Blog, If not specified, they are original. This site uses BY-NC-SAProtocol authenticated.
For reprinting, please indicate the link of the original text:Scheduling a job with Spring programmatically (with fixedRate set dynamically)- Stack Overflow
LIKE (0)
We create, We sharing! Tag every value data your sharing
Submit comments
Cancel comments
emoji picture bold strikethrough center italic check in

Hi,you need to provide your name and email adress!

  • Name (Required)
  • Email (Required)
  • Website