英文:
Reader and writer - do they happen in parallel?
问题
在Spring Batch中,假设我们使用以下方式创建一个步骤:
stepBuilders.get("evalStep")
.<List<Long>, List<Long>>chunk(1)
.reader(reader())
.writer(writer())
.build();
当读取器(reader)产生消息时,写入器(writer)会立刻开始处理它们吗?还是等待读取器完成整个过程后才开始处理?
如果前者成立,是否有一种方式可以设置它们并行运行?
下面是一个显示所期望解决方案的图表。读取器和写入器并行运行。
英文:
In spring batch, let's say we create a step using the following
stepBuilders.get("evalStep")
.<List<Long>, List<Long>>chunk(1)
.reader(reader())
.writer(writer())
.build();
When reader is producing messages, does writer start processing them right away? Or does it wait for reader to be done in its entirety first?
If it is one-than-the-other, is there some way to set it up so that it runs in parallel?
Here is diagram showing desired solution. Reader and Writer run in parallel.
答案1
得分: 1
这是解释文档中的一部分,其中提到了序列图和代码示例:基于块的处理。
> 如果是前者而不是后者,是否有某种方法可以设置它以并行方式运行?
您可以使用多线程步骤来同时处理块内的项目,或者使用分区步骤来并行处理分区。有关更多详细信息,请查看此处的文档:扩展和并行处理。
英文:
The writer does not start until the reader has finished reading a chunk of data. This is explained in the documentation with sequence diagrams and code samples here: Chunk-oriented Processing.
> If it is one-than-the-other, is there some way to set it up so that it runs in parallel?
You can use a multi-threaded step to process items concurrently within chunks, or a partitioned step to process partitions in parallel. For more details about this, take a look at the documentation here: Scaling and Parallel Processing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论