简体   繁体   English

春季批:动态块大小

[英]Spring batch : dynamic chunk size

I have step reads multiple resources, I need to change chunk size depending on number of lines of each file. 我有一步读取多个资源,我需要根据每个文件的行数更改块大小。 is it possible with spring batch to have dynamic chunk size, or there is any other way to do it? Spring Batch是否有可能具有动态的块大小,或者有其他方法可以做到?

You could do Spring Batch Step Partitioning . 您可以执行Spring Batch Step Partitioning Partitioning a step so that the step has several threads that are each processing a chunk of data in parallel. 对一个步骤进行分区,以便该步骤具有多个线程,每个线程并行处理一块数据。 This is beneficial if you have a large chunk of data that can be logically split up into smaller chunks that can be processed in parallel. 如果您有大量的数据可以在逻辑上拆分为可以并行处理的较小的块,这将非常有帮助。 The way this works is that you will define a master step that is responsible for determining the basis of the chunks, and then farming all of those chunks out to a set of slave steps to process each chunk. 这种工作方式是,您将定义一个主要步骤,该步骤负责确定块的基础,然后将所有这些块都植入到一组从属步骤中,以处理每个块。

When configuring the partitioned step, you define a step just as you would any other step by giving it an ID and if required a next step value. 在配置分区步骤时,您可以像定义其他步骤一样定义一个步骤,方法是为其指定一个ID,并根据需要指定下一步骤的值。 Instead of defining the contents of a step as a normal chunk or tasklet , Spring Batch provides a partition tag that requires you to specify the job step to be partitioned and the Partitioner that will be used to determine the chunks of data. 相反,限定台阶的内容作为一个正常的微进程中,Spring Batch的规定,要求您指定要分区作业步骤,这将被用来确定的数据块的分区程序分区标记。 You will also need to define the partition handler that will be processing those steps, in this case we'll be using a ThreadPoolTaskExecutor which will have a thread pool size of 10 and allow them to timeout if they aren't being used. 您还需要定义将处理这些步骤的分区处理程序,在这种情况下,我们将使用ThreadPoolTask​​Executor ,该线程的线程池大小为10,如果不使用它们,则允许它们超时。

<bean id="loadTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="10" />
    <property name="maxPoolSize" value="10" />
    <property name="allowCoreThreadTimeOut" value="true" />
</bean>

Mode information here: https://keyholesoftware.com/2013/12/09/spring-batch-partitioning/ 此处的模式信息: https : //keyholesoftware.com/2013/12/09/spring-batch-partitioning/

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

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