java Spring Batch如何设置Chunk tasklet中每次调用之间的时间间隔

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10349177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:39:59  来源:igfitidea点击:

Spring Batch How to set time interval between each call in a Chunk tasklet

javabatch-processingspring-batch

提问by Abhilash

Team,

团队,

I am doing a technical poc for reading records from a flat file and inserting the data to database.

我正在做一个技术 poc,用于从平面文件读取记录并将数据插入数据库。

I am using chunk task and running this job using spring batch admin successfully.

我正在使用块任务并成功使用 spring 批处理管理运行此作业。

I have to implement the retry policy along with a feature to set the time interval between each retry. I am stuck up with setting the time interval between each retry as chuck doesn't support it directly. Is there any work around for this?

我必须实施重试策略以及设置每次重试之间的时间间隔的功能。我坚持设置每次重试之间的时间间隔,因为卡盘不直接支持它。有什么解决办法吗?

My code is

我的代码是

<batch:job id="importDataJob" job-repository="jobRepository">
  <batch:step id="importDataStep">
    <batch:tasklet transaction-manager="transactionManager">
      <batch:chunk reader="dataReader" writer="dataWriter"  commit-interval="1" retry-limit="3">
        <batch:retryable-exception-classes>
          <batch:include class="javax.naming.ServiceUnavailableException" />
        </batch:retryable-exception-classes>
      </batch:chunk>
    </batch:tasklet>
  </batch:step>
</batch:job>

采纳答案by dma_k

In your case the configuration will look like:

在您的情况下,配置将如下所示:

Spring Batch 2.x

Spring Batch 2.x

<bean id="stepParent" class="org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean" abstract="true">
  <property name="backOffPolicy">
    <bean class="org.springframework.batch.retry.backoff.FixedBackOffPolicy"
      <property name="backOffPeriod" value="2000" />
    </bean>
  </property>
</bean>

<batch:job id="importDataJob" job-repository="jobRepository">
  <batch:step id="importDataStep" parent="stepParent">
     ...
  </batch:step>
</batch:job>

Unfortunately, batchnamespace does not support setting backOffPolicydirectly to step, see BATCH-1441.

不幸的是,batch命名空间不支持backOffPolicy直接设置为step,请参阅BATCH-1441

Spring Batch 3.0

春季批次 3.0

In Spring Batch 3.0 some classes have moved to other packages. This is the the configuration fragment:

在 Spring Batch 3.0 中,一些类已移至其他包。这是配置片段:

<bean id="stepParent"
  class="org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean"         
  abstract="true">

  <property name="backOffPolicy">
    <bean class="org.springframework.retry.backoff.FixedBackOffPolicy">
      <property name="backOffPeriod" value="2000"/>
    </bean>
  </property>

</bean>