gpt4 book ai didi

com.lmax.disruptor.YieldingWaitStrategy类的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 02:32:40 27 4
gpt4 key购买 nike

本文整理了Java中com.lmax.disruptor.YieldingWaitStrategy类的一些代码示例,展示了YieldingWaitStrategy类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YieldingWaitStrategy类的具体详情如下:
包路径:com.lmax.disruptor.YieldingWaitStrategy
类名称:YieldingWaitStrategy

YieldingWaitStrategy介绍

[英]Yielding strategy that uses a Thread.yield() for EventProcessors waiting on a barrier after an initially spinning.

This strategy will use 100% CPU, but will more readily give up the CPU than a busy spin strategy if other threads require CPU resource.
[中]使用线程的屈服策略。初始旋转后等待屏障的事件处理器的yield()。
此策略将使用100%的CPU,但如果其他线程需要CPU资源,则会比繁忙的旋转策略更容易放弃CPU。

代码示例

代码示例来源:origin: crossoverJie/JCSprout

new YieldingWaitStrategy());

代码示例来源:origin: LMAX-Exchange/disruptor

@Override
public long waitFor(
  final long sequence, Sequence cursor, final Sequence dependentSequence, final SequenceBarrier barrier)
  throws AlertException, InterruptedException
{
  long availableSequence;
  int counter = SPIN_TRIES;
  while ((availableSequence = dependentSequence.get()) < sequence)
  {
    counter = applyWaitMethod(barrier, counter);
  }
  return availableSequence;
}

代码示例来源:origin: Graylog2/graylog2-server

private WaitStrategy getWaitStrategy(String waitStrategyName, String configOptionName) {
  switch (waitStrategyName) {
    case "sleeping":
      return new SleepingWaitStrategy();
    case "yielding":
      return new YieldingWaitStrategy();
    case "blocking":
      return new BlockingWaitStrategy();
    case "busy_spinning":
      return new BusySpinWaitStrategy();
    default:
      LOG.warn("Invalid setting for [{}]:"
          + " Falling back to default: BlockingWaitStrategy.", configOptionName);
      return new BlockingWaitStrategy();
  }
}

代码示例来源:origin: com.lmax/disruptor

@Override
public long waitFor(
  final long sequence, Sequence cursor, final Sequence dependentSequence, final SequenceBarrier barrier)
  throws AlertException, InterruptedException
{
  long availableSequence;
  int counter = SPIN_TRIES;
  while ((availableSequence = dependentSequence.get()) < sequence)
  {
    counter = applyWaitMethod(barrier, counter);
  }
  return availableSequence;
}

代码示例来源:origin: Graylog2/graylog2-server

protected WaitStrategy getWaitStrategy(String waitStrategyName, String configOptionName) {
  switch (waitStrategyName) {
    case "sleeping":
      return new SleepingWaitStrategy();
    case "yielding":
      return new YieldingWaitStrategy();
    case "blocking":
      return new BlockingWaitStrategy();
    case "busy_spinning":
      return new BusySpinWaitStrategy();
    default:
      log.warn("Invalid setting for [{}]:"
              + " Falling back to default: BlockingWaitStrategy.", configOptionName);
      return new BlockingWaitStrategy();
  }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public long waitFor(final long sequence, Sequence cursor, final Sequence dependentSequence, final SequenceBarrier barrier)
  throws AlertException, InterruptedException
{
  long availableSequence;
  int counter = SPIN_TRIES;
  while ((availableSequence = dependentSequence.get()) < sequence)
  {
    counter = applyWaitMethod(barrier, counter);
  }
  return availableSequence;
}

代码示例来源:origin: LMAX-Exchange/disruptor

@Test
  public void shouldWaitForValue() throws Exception
  {
    assertWaitForWithDelayOf(50, new YieldingWaitStrategy());
  }
}

代码示例来源:origin: xiaoguichao/mr

@Override
public long waitFor(
  final long sequence, Sequence cursor, final Sequence dependentSequence, final SequenceBarrier barrier)
  throws AlertException, InterruptedException
{
  long availableSequence;
  int counter = SPIN_TRIES;
  while ((availableSequence = dependentSequence.get()) < sequence)
  {
    counter = applyWaitMethod(barrier, counter);
  }
  return availableSequence;
}

代码示例来源:origin: fengjiachun/Jupiter

break;
case YIELDING_WAIT:
  waitStrategy = new YieldingWaitStrategy();
  break;
case BUSY_SPIN_WAIT:

代码示例来源:origin: mzheravin/exchange-core

@Override
public long waitFor(
    final long sequence, Sequence cursor, final Sequence dependentSequence, final SequenceBarrier barrier)
    throws AlertException, InterruptedException {
  long availableSequence;
  int counter = SPIN_TRIES;
  while ((availableSequence = dependentSequence.get()) < sequence) {
    counter = applyWaitMethod(barrier, counter);
  }
  return availableSequence;
}

代码示例来源:origin: fengjiachun/Jupiter

break;
case YIELDING_WAIT:
  waitStrategy = new YieldingWaitStrategy();
  break;
case BUSY_SPIN_WAIT:

代码示例来源:origin: org.projectreactor/reactor-core

/**
 * Set {@link com.lmax.disruptor.YieldingWaitStrategy} as wait strategy.
 *
 * @return {@literal this}
 */
public ProcessorSpec<T> yieldingWaitStrategy() {
  this.waitStrategy = new YieldingWaitStrategy();
  return this;
}

代码示例来源:origin: com.srotya/linea

@SuppressWarnings("unchecked")
public BoltExecutorWrapper(TupleFactory<E> factory, ExecutorService pool, Bolt<E> processor) {
  this.pool = pool;
  this.bolt = processor;
  disruptor = new Disruptor<>(factory, 1024 * 8, pool, ProducerType.MULTI, new YieldingWaitStrategy());
  disruptor.handleEventsWith(this);
}

代码示例来源:origin: camunda/camunda-bpm-reactor

public AgileWaitingStrategy() {
 this(new BlockingWaitStrategy(), new YieldingWaitStrategy());
}

代码示例来源:origin: mzheravin/exchange-core

public WaitStrategy create() {
  switch (this) {
    case SLEEPING:
      return new SleepingWaitStrategy();
    case BUSY_SPIN:
      return new BusySpinWaitStrategy();
    case YIELDING:
    default:
      return new YieldingWaitStrategy();
  }
}

代码示例来源:origin: org.graylog2/graylog2-server

private WaitStrategy getWaitStrategy(String waitStrategyName, String configOptionName) {
  switch (waitStrategyName) {
    case "sleeping":
      return new SleepingWaitStrategy();
    case "yielding":
      return new YieldingWaitStrategy();
    case "blocking":
      return new BlockingWaitStrategy();
    case "busy_spinning":
      return new BusySpinWaitStrategy();
    default:
      LOG.warn("Invalid setting for [{}]:"
          + " Falling back to default: BlockingWaitStrategy.", configOptionName);
      return new BlockingWaitStrategy();
  }
}

代码示例来源:origin: org.graylog2/graylog2-server

protected WaitStrategy getWaitStrategy(String waitStrategyName, String configOptionName) {
  switch (waitStrategyName) {
    case "sleeping":
      return new SleepingWaitStrategy();
    case "yielding":
      return new YieldingWaitStrategy();
    case "blocking":
      return new BlockingWaitStrategy();
    case "busy_spinning":
      return new BusySpinWaitStrategy();
    default:
      log.warn("Invalid setting for [{}]:"
              + " Falling back to default: BlockingWaitStrategy.", configOptionName);
      return new BlockingWaitStrategy();
  }
}

代码示例来源:origin: com.srotya/linea

new YieldingWaitStrategy());
clients = new ArrayList<>(clientThreadCount);
for (int i = 0; i < clientThreadCount; i++) {

代码示例来源:origin: cn.jeeweb/jeeweb-common-base

@SuppressWarnings("deprecation")
@PostConstruct
private void start() {
  // Executor that will be used to construct new threads for consumers
  Executor executor = Executors.newCachedThreadPool();
  // The factory for the event
  TaskEventFactory factory = new TaskEventFactory();
  // Specify the size of the ring buffer, must be power of 2.
  // Construct the Disruptor
  // 单线程模式,获取额外的性能
  disruptor = new Disruptor<TaskEvent>(factory, bufferSize, executor, ProducerType.SINGLE,
      new YieldingWaitStrategy());
  List<TaskHandler> TaskHandlers = new ArrayList<>();
  for (int i = 0; i < handlerCount; i++) {
    TaskHandlers.add(new TaskHandler());
  }
  disruptor.handleExceptionsWith(new IgnoreExceptionHandler());
  // 多个消费者,每个消费者竞争消费不同数据
  disruptor.handleEventsWithWorkerPool(TaskHandlers.toArray(new TaskHandler[TaskHandlers.size()]));
  // Start the Disruptor, starts all threads running
  disruptor.start();
  // Get the ring buffer from the Disruptor to be used for publishing.
  RingBuffer<TaskEvent> ringBuffer = disruptor.getRingBuffer();
  taskEventProducer = new TaskEventProducer(ringBuffer);
}

代码示例来源:origin: com.yahoo.omid/tso-server

@Inject
RetryProcessorImpl(MetricsRegistry metrics, CommitTable commitTable,
          ReplyProcessor replyProc, Panicker panicker)
  throws InterruptedException, ExecutionException {
  this.commitTableClient = commitTable.getClient().get();
  this.writer = commitTable.getWriter().get();
  this.replyProc = replyProc;
  WaitStrategy strategy = new YieldingWaitStrategy();
  retryRing = RingBuffer.<RetryEvent>createSingleProducer(
      RetryEvent.EVENT_FACTORY, 1<<12, strategy);
  SequenceBarrier retrySequenceBarrier = retryRing.newBarrier();
  BatchEventProcessor<RetryEvent> retryProcessor = new BatchEventProcessor<RetryEvent>(
      retryRing,
      retrySequenceBarrier,
      this);
  retryProcessor.setExceptionHandler(new FatalExceptionHandler(panicker));
  retryRing.addGatingSequences(retryProcessor.getSequence());
  ExecutorService retryExec = Executors.newSingleThreadExecutor(
      new ThreadFactoryBuilder().setNameFormat("retry-%d").build());
  retryExec.submit(retryProcessor);
  // Metrics
  retriesMeter = metrics.meter(name("tso", "retries"));
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com