首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将一个庞大的集合传递给Spring批处理步骤的最佳方法是什么?

将一个庞大的集合传递给Spring批处理步骤的最佳方法是什么?
EN

Stack Overflow用户
提问于 2014-01-07 15:22:27
回答 1查看 1.8K关注 0票数 0

Use case:

  1. 一次将数据集X(从数据库)读入集合C。集合大小可以说是5000。
  2. 使用集合C处理/充实Spring批处理步骤中的项(例如enrichStep)

如果C远大于通过ExecutionContext传递的内容,我们如何使它在ItemProcessor of enrichStep中可用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-07 15:49:39

在您的enrichStep中添加一个StepExecutionListener.beforeStep并在HugeCollectionBeanHolder bean中加载您的大量集合。

这样,您将只加载一次集合(当步骤启动或重新启动时),而不将其保存到执行上下文中。在您的丰富处理器连接HugeCollectionBeanHolder以访问庞大的集合。

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20975355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档