0

テーブルから読み取り、文字列を渡し、@service を使用してデータを Redis インスタンスに格納するジョブを構成しました。

ご覧のとおり、ジョブは完了しています。

INFO  SimpleJobLauncher - Job: [FlowJob: [name=populateCacheWithCalendarData]] completed with the following

パラメータ: [{time=2016-06-22T08:46:09.001}] および次のステータス: [COMPLETED]

そして、ループのように何度も起動されます:

INFO ScheduledTasks - 実行中のスケジュールされたタスク [ populateCacheWithCalendarData ] 25438: INFO SimpleJobLauncher - ジョブ: [FlowJob: [name=populateCacheWithCalendarData]] が次のパラメーターで起動されました: [{time=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);
   }
}

しばらくすると停止するため、なぜそれを行っているのかわかりません。

前もって感謝します

4

1 に答える 1

0

問題は、* がスケジューラーに毎秒、毎分、そして息子のようにジョブを起動させることでした。私はそれを次のように置き換えます:

 @Scheduled(cron = "0 0 */14 * * *")

これが他の人に役立つことを願っています

于 2016-09-13T06:33:28.743 に答える