繁体   English   中英

无法配置Spring Batch以运行作业

[英]Cant configure Spring Batch to run jobs consequently

我使用以下作业启动器来启动我的弹簧批处理作业:

  <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository"/>
    <property name="taskExecutor">
      <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
    </property>
  </bean>

我的工作定义是

  <job id="bulkExportJob" restartable="false" xmlns="http://www.springframework.org/schema/batch">
    <description>Exports an application to pdf in a bulk operation</description>

    <step id="startExport" next="exportFileTree">
      <description>Do something to start the export</description>
      <tasklet ref="startBulkActionTasklet"/>
    </step>

    <step id="exportFileTree" next="zipFileTree">
      <description>Export the application</description>
      <tasklet>
        <chunk reader="bulkActionTargetReader" writer="bulkExportFileTreeWriter" commit-interval="1" skip-limit="100000000">
          <skippable-exception-classes>
            <!-- Exceptions are handled internally to the Writer so exception should not be treated as failures -->
            <include class="java.lang.Exception"/>
          </skippable-exception-classes>
        </chunk>
      </tasklet>
      <listeners>
        <listener ref="promotionListener"/>
      </listeners>
    </step>

    <step id="zipFileTree" next="sendEmail">
      <description>Creates a zip file</description>
      <tasklet ref="bulkExportZipWriter"/>
    </step>

    <step id="sendEmail" next="finishExport">
      <description>Send notification email</description>
      <tasklet ref="bulkExportSendNotification"/>
    </step>


    <step id="finishExport">
      <description>Finalise the export</description>
      <tasklet ref="finishBulkActionTasklet"/>
    </step>

  </job>

我的目的是一次运行一个工作并排队所有其他传入的工作。 但是从日志文件中我可以看到所有作业并行运行。 正如您从代码片段中看到的那样,我没有任何其他代码可以并行生成spring批处理,但它仍然可以。 你能指出我做错了什么吗?

您正在使用SimpleAsyncTaskExecutor ,它正在运行作业异步并为每个作业创建新线程:

TaskExecutor实现,为每个任务激活一个新线程,异步执行它。

支持通过“concurrencyLimit”bean属性限制并发线程。 默认情况下,并发线程数不受限制。

注意:此实现不重用线程! 相反,请考虑使用线程池TaskExecutor实现,尤其是执行大量短期任务。

正如所建议的,如果您绝对需要SimpleAsyncTaskExecutor您可以将concurrencyLimit设置为1(使用throttle-limit="1"属性)并且一次有1个作业,但是您可以使用默认的SyncTaskExecutor ,它将按顺序运行作业,当一个完成其他作业时运行(根据您想要的解释进行猜测)。

尝试将throttle-limit="1"到tasklet定义。 http://docs.spring.io/spring-batch/trunk/reference/html/scalability.html上的文档表明它默认为4。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM