作为批处理 API (JSR-352) 的新手,我在建模以下(简化的)场景时遇到一些困难:
- 假设我们有一个
Batchlet
首先生成一组动态文件step
.
- 一秒钟后
step
,所有这些文件必须在中单独处理chunk
s (via ItemReader
, ItemProcessor
and ItemWriter
)产生一组新的文件。
- 在第三个
step
这些新文件需要打包到一个大档案中。
我找不到定义第二步的方法,因为规范似乎没有提供循环构造(在我的理解中partition
, split
and flow
仅适用于具有已知固定大小的集合)。
工作 xml 定义是什么样子的?我是否必须在第二步中放弃分块的想法,或者是否必须将任务分成多个作业?还有其他选择吗?
您可以使用分区映射器 https://jakarta.ee/specifications/batch/1.0/apidocs/javax/batch/api/partition/PartitionMapper.html以编程方式为分区步骤定义动态数量的分区。
映射器需要创建一个分区计划设置分区数量并为每个分区提供特定于分区的属性的对象。
您的地图绘制者映射分区()方法将类似于以下大纲:
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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)