本文整理了Java中com.lmax.disruptor.YieldingWaitStrategy
类的一些代码示例,展示了YieldingWaitStrategy
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YieldingWaitStrategy
类的具体详情如下:
包路径:com.lmax.disruptor.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"));
}
内容来源于网络,如有侵权,请联系作者删除!