What's the best way to pass a huge collection to a Spring Batch Step?

十年热恋 提交于 2019-12-04 22:13:26
Luca Basso Ricci

In your enrichStep add a StepExecutionListener.beforeStep and load your huge collection in a HugeCollectionBeanHolder bean.
In this way you will load collection only once (when step start or re-start) and without persist it into execution context. In your enrich processor wire the HugeCollectionBeanHolder to access huge collection.

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...
}

You can also look at Spring Batch: what is the best way to use, the data retrieved in one TaskletStep, in the processing of another step

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!