Disruptor核心(四)WaitStrategy

本文介绍了com.lmax.disruptor中的三种等待策略:BlockingWaitStrategy、SleepingWaitStrategy及YieldingWaitStrategy。这些策略决定了消费者如何等待生产者将事件放入Disruptor,包括它们的特点、适用场景以及对CPU资源的利用情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

com.lmax.disruptor.WaitStrategy

  • 决定一个消费者如何等待生产者将Event置入Disruptor;
  • 其所有实现都是针对消费者线程的;

主要策略有

  • com.lmax.disruptor.BlockingWaitStrategy
  • com.lmax.disruptor.SleepingWaitStrategy
  • com.lmax.disruptor.YieldingWaitStrategy

com.lmax.disruptor.BlockingWaitStrategy

  • 最低效的策略,但其对CPU的消耗最小,并且在各种部署环境中能提供更加一致的性能表现;
  • 内部维护了一个重入锁ReentrantLock和Condition;

com.lmax.disruptor.SleepingWaitStrategy

  • 性能表现和com.lmax.disruptor.BlockingWaitStrategy差不多,对CPU的消耗也类似,但其对生产者线程的影响最小,适合用于异步日志类似的场景;
  • 是一种无锁的方式;

com.lmax.disruptor.YieldingWaitStrategy

  • 性能最好,适合用于低延迟的系统;在要求极高性能且事件处理线程数小于CPU逻辑核心树的场景中,推荐使用此策略;例如,CPU开启超线程的特性;
  • 也是无锁的实现,只要是无锁的实现,signalAllWhenBlocking()都是空实现;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值