我有两个作业配置为与作业启动器并行运行,并且工作正常,但我希望在启动时并行运行作业,而不是按计划运行。我在网上找到的所有内容都显示了仅在计划与自定义作业启动器一起运行以及手动添加spring.batch.job.enabled=false
时如何配置它们以并行运行。安排好时间后,可以手动注入要使用的自定义作业启动器,但是不知道将自定义作业启动器放在哪里
示例1的工作
@Bean("Job1")
Job myJobOne(JobCompletionNotificationListener listener) {
return jobBuilderFactory.get("myJobOne")
.incrementer(new RunIdIncrementer())
.listener(listener)
.flow(myJobOneStep())
.end()
.build();
}
@Bean
public Step myJobOneStep() {
return stepBuilderFactory.get("myJobOneStep")
.<Object, Object>chunk(10000)
.reader(myReader())
.processor(myProcessor())
.writer(myWriter())
.taskExecutor(CustomExecutor.taskExecutor()).build();
}
我的班级安排他们上课
@Configuration
@EnableBatchProcessing
@EnableScheduling
@EnableAsync
public class process {
private static final Logger LOGGER = LoggerFactory.getLogger(process.class);
@Autowired
@Qualifier("Job1")
Job myJobOne;
@Autowired
@Qualifier("Job2")
Job myJobTwo;
@Autowired
private JobLauncher customJobLauncher;
@Scheduled(fixedRate = 900000000 )
public void run1(){
Map<String, JobParameter> confMap = new HashMap<>();
confMap.put("time", new JobParameter(System.currentTimeMillis()));
JobParameters jobParameters = new JobParameters(confMap);
try {
customJobLauncher.run(myJobOne, jobParameters);
}catch (Exception ex){
LOGGER.error(ex.getMessage());
}
}
@Scheduled(fixedRate = 900000000)
public void run2(){
Map<String, JobParameter> confMap = new HashMap<>();
confMap.put("time", new JobParameter(System.currentTimeMillis()));
JobParameters jobParameters = new JobParameters(confMap);
try {
customJobLauncher.run(myJobTwo, jobParameters);
}catch (Exception ex){
LOGGER.error(ex.getMessage());
}
}
}
@Configuration
@EnableAutoConfiguration
@EnableScheduling
@EnableBatchProcessing
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}