私のソース テーブルには 10 個のレコードがあり、10 個のレコードを読み取り、それらを処理する必要があり、その処理されたレコードをターゲット テーブルに書き込む必要があります。この 10 レコードに対して、2 つのパーティションを作成しました。しかし、私の実際のプロジェクトでは、毎日処理する必要があるレコードの数がわからないので、必要なパーティションの数をどのように決定できますか? パーティションを動的に追加することはできますか? JSR 352 with Liberty Profile - how to implement checkpointing when ItemReader dos DB queryで私の poc コードを見つけてください。
1 に答える
2
Use a PartitionMapper to dynamically define the number of partitions in a partitioned step.
This runs at the beginning of the step and builds a PartitionPlan which defines the number of partitions and the Properties for each partition.
In the XML, your <partition>
element should include a child <mapper>
element rather than the child <plan>
element you'd use to define the number of partitions statically.
But you otherwise perform the substitution similarly using the partitionPlan property substitution.
E.g.
<step id="mappedStep">
<batchlet ref="MyBatchlet">
<properties>
<property name="xx" value="#{partitionPlan['xx']}" />
</properties>
</batchlet>
<partition>
<mapper ref="MyMapper">
<properties>
<property name="mapperProp" value="#{jobProperties['mapperProp']}" />
</properties>
</mapper>
</partition>
</step>
Your PartitionMapper could build the PartitionPlan with something like this:
import javax.batch.api.partition.PartitionMapper;
import javax.batch.api.partition.PartitionPlan;
import javax.batch.api.partition.PartitionPlanImpl;
// ...
@Named("MyMapper")
public class MyPartitionMapper implements PartitionMapper {
@Inject @BatchProperty
String mapperProp; // FROM JSL, USE IF YOU WANT, NOT USED HERE
@Override
public PartitionPlan mapPartitions() throws Exception {
numPartitions = calculateNumPartitions() // YOUR LOGIC HERE
Properties[] props = new Properties[numPartitions];
Integer i;
for (i = 0; i < numPartitions; i++) {
props[i] = new Properties();
props[i].setProperty("xx", "xxVal" + i); // SUPPLY PER-PARTITION PROPERTY 'xx'
props[i].setProperty("yy", "yyVal" + i); // SUPPLY PER-PARTITION PROPERTY 'yy'
}
PartitionPlan partitionPlan = new PartitionPlanImpl();
partitionPlan.setPartitions(numPartitions);
partitionPlan.setPartitionProperties(props);
partitionPlan.setPartitionsOverride(false);
return partitionPlan;
}
}
于 2016-06-06T14:10:55.583 に答える