jsr352 - 批处理作业定义: How to run a dynamically-calculated number of partitions?

标签 jsr352 java-batch

作为批处理 API (JSR-352) 的新手,我在建模以下(简化的)场景时遇到一些困难:

  1. 假设我们有一个 Batchlet在第一个 step 中生成一组动态文件.
  2. 马上 step ,所有这些文件必须在 chunk 中单独处理s(通过 ItemReaderItemProcessorItemWriter )生成一组新文件。
  3. 第三个 step这些新文件需要打包到一个大存档中。

我找不到定义第二步的方法,因为规范似乎没有提供循环构造(根据我的理解, partitionsplitflow 仅适用于具有已知固定尺寸)。

工作 xml 定义是什么样子的?我是否必须在第二步中放弃分块的想法,或者是否必须将任务分成多个作业?还有其他选择吗?

最佳答案

您可以使用PartitionMapper 以编程方式为分区步骤定义动态数量的分区。

映射器需要创建一个 PartitionPlan 对象,该对象设置分区数量并为每个分区提供特定于分区的属性。

您的映射器的 ma​​pPartitions() 方法将类似于以下轮廓:

public PartitionPlan mapPartitions() throws Exception {

    int numPartitions = // calculate number of partitions, however you want

    // create an array of Properties objects, one for each partition
    Properties[] props = new Properties[numPartitions];

    for (int i = 0; i < numPartitions; i++) {
        // create a Properties object for this partition
        props[i] = new Properties();

        props[i].setProperty("abc", ...);
        props[i].setProperty("xyz", ...);
    }

    // use the built-in PartitionPlanImpl from the spec or your own impl
    PartitionPlan partitionPlan = new PartitionPlanImpl(); 
    partitionPlan.setPartitions(numPartitions);

    // cet the Properties[] onto your plan
    partitionPlan.setPartitionProperties(props);

    return partitionPlan;
}

然后您可以像这样引用特定于分区的属性值(这与引用静态定义的分区属性的方式相同):

    <batchlet ref="myBatchlet">
        <properties>
            <property name="propABC" value="#{partitionPlan['abc']}" />
            <property name="propXYZ" value="#{partitionPlan['xyz']}" />
        </properties>
    </batchlet>

关于jsr352 - 批处理作业定义: How to run a dynamically-calculated number of partitions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58427625/

相关文章:

java.util.list 的 Java EE 7 Batch (JSR-352) 语法?

spring-batch - JSR 352(用于批处理的 Java)有哪些实现?

java - JSR 352 : Is it possible to run different partitions of the same step in the same job in Multiple JVMs?

java-ee-7 - 如何在 JSR-352 Java Batch 应用程序中使用 JSL 中的动态值

java - 通过JobOperator停止JobInstance

java - WebSphere Liberty - 批量读取器/写入器/等。使用不同的作业参数值重新运行作业时不显示更新的值

java - 如何在 block 处理中实现文件更新逻辑(Java Batch - JSR352)

java - JSR 352 : Wildfly9/JBeret - How to call a batch job that it is not contained at the same deployment file level

java - 从命令提示符运行程序时未找到 Classnotfound