SpringBoot定时任务

it2022-05-05  164

SpringBoot自带的定时任务

在@Configuration配置文件下进行任务的并行度控制 @Bean public ScheduledThreadPoolExecutor scheduledExecutorService() { return new ScheduledThreadPoolExecutor(10); } 编写定时任务类 import java.util.Calendar; import java.util.Date; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Configurable; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component @Configurable @EnableScheduling public class Job { @Scheduled(fixedDelay = 1000 * 5) public void getOrders() throws Exception { System.out.println("每5秒打印一次"); } }

SpringBoot与quartz的整合


最新回复(0)