读者和写者 – 他们是否并行进行?

huangapple go评论38阅读模式
英文:

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(&quot;evalStep&quot;)
                .&lt;List&lt;Long&gt;, List&lt;Long&gt;&gt;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.

huangapple
  • 本文由 发表于 2023年2月16日 08:05:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466586.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定