在v1版本的MyDisruptor实现单生产者、单消费者功能后。按照计划,v2版本的MyDisruptor需要支持多消费者和允许设置消费者组间的依赖关系。
由于这篇文章是一系列博客的一部分,我们需要了解前一篇博客的内容,以便更好地理解这篇博客。
[En]
Since the article is part of a series of blogs, we need to know the content of the previous blog in order to better understand this blog.
- disruptor中的生产者和消费者是互相制约的,生产者的生产速度不能过快,在逻辑上队列已满时需要阻塞等待消费者进行消费,直到队列不满。
- 为了支持多个消费者,上述描述需要调整:即生产商的生产速度不能太快。从逻辑上讲,当队列已满时,您需要阻塞并等待“最慢的消费者”完成消费,直到队列不满意为止。
to support multiple consumers, the above description needs to be adjusted: that is, the production speed of the producer cannot be too fast. Logically, when the queue is full, you need to block and wait for the " * slowest consumer * " to complete the consumption until the queue is dissatisfied.*
- disruptor中每个消费者都拥有自己的消费序列号,生产者在生产时需要保证生产的序列号不能覆盖任何一个消费者,即生产者的序列号不能超过最慢的消费者序列号一圈(Producer.Sequence - SlowestConsumer.Sequence
```java
package mydisruptor;
import mydisruptor.util.SequenceUtil;
import mydisruptor.waitstrategy.MyWaitStrategy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.locks.LockSupport;
/**