SoFunction
Updated on 2025-04-13

How to configure Scheduler timer in Springboot

Springboot configures Scheduler timer

1. Add @EnableScheduling annotation to the startup class

Turn on the timer

2. Set timer tasks (both interval and cron expression are OK)

package .;
import ;
import ;

@Component
public class MyScheduler {

    @Scheduled(fixedRate = 1000) //Execute every 2 seconds    public void statusCheck() {
        ("【*** A ***】Interval Scheduling");
    }

    @Scheduled(cron="* * * * * ?")  //Called once per second    public void removeToHis() {
        try {
            //Sleep for 3 seconds            (3000);
        } catch (InterruptedException e) {
            ();
        }
        ("【*** B ***】cron dispatching");
    }
}

3. Configure the scheduling pool

package .;
import ;
import ;
import ;
import ;

/**
  * Used for parallel scheduling
  */
@Configuration
public class SchedulerConfig implements SchedulingConfigurer {

    @Override
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        ((100));
    }
}

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.