上篇文章简单介绍了怎么在SpringBoot项目中运用简单的定时(间隔)任务,并且举例用的是单个任务,如果是多个定时(间隔)任务,并且想同时执行,应该怎么办?
首先经过了解,@Scheduled是单线程的,如果有多个定时任务,势必需要前一个任务执行完才会执行后面的任务,先放代码:
package com.wl.standard.task;
import com.wl.standard.entity.City;
import com.wl.standard.entity.CityGdp;
import com.wl.standard.entity.CityRail;
import com.wl.standard.service.CityGdpService;
import com.wl.standard.service.CityRailService;
import com.wl.standard.service.CityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.List;
/**
* 间隔任务
* @author wl
* @date 2021/12/23
*/
@Configuration
@Slf4j
@PropertySource("class