将大量集合传递到Spring批处理步骤的最佳方式是什么? [英] What's the best way to pass a huge collection to a Spring Batch Step?

查看:17
本文介绍了将大量集合传递到Spring批处理步骤的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Use case:

  1. 将数据集X(从数据库)一次性读取到集合C。[集合大小可以是5000]
  2. 使用集合C处理/丰富Spring批处理步骤中的项目(例如丰富步骤)

如果C远远大于可以通过ExecutionContext传递的值,我们如何使其在丰富步骤的ItemProcessor中可用?

推荐答案

在您的enrichStep中添加StepExecutionListener.beforeStep并将您的巨大集合加载到HugeCollectionBeanHolderBean中。
这样,您将只加载一次集合(在步骤开始或重新启动时),并且不会将其持久化到执行上下文中。 在您丰富处理器中连接HugeCollectionBeanHolder以访问巨大的集合。

class HugeCollectionBeanHolder {
 Collection<Item> hudeCollection;

 void setHugeCollection(Collection<Item> c) { this.hugeCollection = c;}
 Collection<Item> getHugeCollection() { return this.hugeCollection;}
}

class MyProcessor implements ItemProcessor<Input,Output> {
 HugeCollectionBeanHolder hcbh;

 void setHugeCollectionBeanHolder(HugeCollectionBeanHolder bean) { this.hcbh = bean;}

 // other methods...
}

您还可以查看Spring Batch: what is the best way to use, the data retrieved in one TaskletStep, in the processing of another step

这篇关于将大量集合传递到Spring批处理步骤的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆