테이블에서 읽은 일부 문자열을 전달한 다음 @service를 사용하여 Redis 인스턴스에 데이터를 저장하는 작업을 구성했습니다.작업 완료 후 일괄 처리가 계속 실행됩니다.
작업이 당신이 볼 수있는 완료 :
INFO SimpleJobLauncher - Job: [FlowJob: [name=populateCacheWithCalendarData]] completed with the following
매개 변수 : [{시간 = 2016-06-22T08 : 46 : 09.001}] 다음과 같은 상태 : [COMPLETED]
그리고 그것은 루프에서와 같이 또 다시 시작됩니다 :
정보의 ScheduledTasks - 모델명 : SCH 실행 eduled 작업 [ populateCacheWithCalendarData] 25438 : 정보 SimpleJobLauncher - 작업 : [FlowJob : [이름 = populateCacheWithCalendarData]]를 다음 매개 변수와 함께 시작 : [{시간 = 2016-06-22T08 : 46 : 10}]
내가 예약 된 작업은 다음과 같이 구성되어있다 :
@Slf4j
@Component
public class ScheduledTasks {
@Autowired
JobLauncher jobLauncher;
@Autowired
JobRegistry jobRegistry;
// scheduled every 14 hours
@Scheduled(cron = "* * */1 * * *")
public void doPopulateCacheWithCalendarDataJob()
throws NoSuchJobException, JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
// given
log.info("Running Scheduled task [ populateCacheWithCalendarData ]");
Job calendarJob = jobRegistry.getJob("populateCacheWithCalendarData");
JobParametersBuilder paramsBuilder = new JobParametersBuilder().addString("time", LocalDateTime.now().toString());
// then
jobLauncher.run(calendarJob, paramsBuilder.toJobParameters());
}
}
작업 구성 :
@Configuration
@EnableBatchProcessing
public class CalendarBatchConfiguration extends AbstractBatchConfiguration {
@Bean
public Job populateCacheWithCalendarData() {
return jobBuilderFactory.get("populateCacheWithCalendarData")
.incrementer(new RunIdIncrementer())
.flow(calendarStep1())
.end()
.build();
}
/**
* Look up hotel tickers and creates a csv file with them.
*
* @return ariStep1
*/
@Bean
public Step calendarStep1() {
return stepBuilderFactory.get("calendarStep1")
.<Hotel, String>chunk(100)
.reader(calendarReader())
.processor(calendarProcessor())
.writer(calendarWriter2())
.build();
}
@Bean
public JdbcCursorItemReader<Hotel> calendarReader() {
JdbcCursorItemReader<Hotel> reader = new JdbcCursorItemReader<>();
reader.setSql("SELECT identificador, es_demo FROM instanciasaplicaciones WHERE es_demo = 0 AND version = 6");
reader.setDataSource(this.dataSource);
reader.setRowMapper((resultSet, i) -> new Hotel(resultSet.getString("identificador"), resultSet.getString("es_demo")));
return reader;
}
@Bean
public HotelItemProcessor calendarProcessor() {
return new HotelItemProcessor();
}
@Bean
public CalendarItemWriter calendarWriter2() {
return new CalendarItemWriter();
}
}
프로세서 및 작가 : 단지의 경우에
@Slf4j
public class CalendarItemProcessor implements ItemProcessor<String, String> {
@Override
public String process(String item) throws Exception {
log.info("Processing calendar hotel Ticker [" + item + "]");
return item;
}
}
@Slf4j
public class CalendarItemWriter implements ItemWriter<String> {
@Autowired
private CalendarService calendarService;
@Override
public void write(List<? extends String> hotelTickers) throws Exception {
log.info("Creating calendar entry in Cache for items... ", hotelTickers.toString());
hotelTickers.forEach(this::createOrUpdateCache);
}
/**
* Use service to store calendar values into the cache.
*
* @param hotelTicker hotelTicker
*/
private void createOrUpdateCache(String hotelTicker) {
// store calendar ari values
calendarService.createOrUpdateCalendarByHotelTicker(hotelTicker);
}
}
주요 응용 프로그램 :
/**
* Main entry point for the Application.
*/
@EnableScheduling
@EnableTransactionManagement
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
내가 때문에 일부 오랜만에 멈출 것을하고있는 이유를 모르겠어요. 사전