【问题标题】:Monitor currently running process via spring batch process and notify if the throttle limit is reached通过 spring 批处理监控当前正在运行的进程,并通知是否达到油门限制
【发布时间】:2021-04-16 01:46:49
【问题描述】:

我有一个 Spring Boot Web 应用程序,我想通过批处理从 CSV 文件上传详细信息。文件可以从任何位置上传,我想一次限制处理 3 个作业。如果已经在处理 3 个文件,我们必须将该信息提供给 UI,如“已达到油门限制。过一段时间再试”。我怎么能做到这一点? 我当前的 flow.xml 是主从方法

    <!-- partitioner job -->
    <job id="partitionJob" xmlns="http://www.springframework.org/schema/batch">

    <!-- master step -->
            <step id="masterStep">
              <partition step="slave" partitioner="partitioner">
                    <handler grid-size="1" task-executor="taskExecutor" />
               </partition>
            </step>

    </job>

    <!-- each thread will run this job, with different stepExecutionContext
    values. -->
    <step id="slave" xmlns="http://www.springframework.org/schema/batch">
            <tasklet transaction-manager="transactionManager"  throttle-limit="3">
                <chunk reader="itemReader" processor="userItemProcessor" writer="itemWriter"
               commit-interval="10" />
                 <listeners>
                        <listener ref="stepJobListener" />
                  </listeners>
            </tasklet>
    </step>

【问题讨论】:

    标签: spring spring-boot spring-batch batch-processing


    【解决方案1】:

    您在步骤上设置的throttle-limit="3" 用于将运行您的步骤的线程。对于您的用例,您应该寻找一种方法来配置JobLauncher 使用的TaskExecutor 以限制并发作业的数量。

    例如,您可以将JobLauncher 配置为ThreadPoolTaskExecutor,然后将queueCapacity 设置为3。使用此配置,如果您一次提交超过3 个作业,则第4 个提交的作业将失败并且您可以在 UI 中显示错误。

    对于监控部分,您可以检查执行器的队列大小,如Spring framework monitoring ThreadPoolTaskExecutor queue size中所述

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多