package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @SpringBootApplication @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class PlatoonHolyoverApplication { public static void main(String[] args) { SpringApplication.run(PlatoonHolyoverApplication.class, args); } //多线程运行定时任务 @Bean public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.setPoolSize(6); return taskScheduler; } }
package com.example.demo.com; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component @EnableAsync @EnableScheduling public class SchedualConfig { @Autowired SynDataHoilday synDataHoilday; @Autowired SynDataOvertime synDataOvertime; @Autowired SynDataPost synDataPost; @Autowired SynDataOrganization synDataOrganization; @Autowired SynDataShiftRule synDataShiftRule; // 同步请假汇总表 @Async @Scheduled(cron = "0 30 0 * * ?") public void taskA() { // 执行你的业务逻辑 synDataHoilday.synHoilday(); } // 同步加班汇总表 @Async @Scheduled(cron = "0 30 0 * * ?") public void taskB() { synDataOvertime.synOvertime(); } //同步崗位 @Async @Scheduled(cron = "0 30 0 * * ?") public void taskC() { synDataPost.synDataPost(); } //同步组织 @Async @Scheduled(cron = "0 30 0 * * ?") public void taskD() { synDataOrganization.synDataOrganization(); } //同步班次信息 @Async @Scheduled(cron = "0 30 0 * * ?") public void taskE() { synDataShiftRule.synDataShiftRule(); } }
标签:Scheduled,springboot,springframework,org,scheduling,import,多线程,public From: https://www.cnblogs.com/zhouyunchao/p/17421310.html