当前位置: 首页>>代码示例>>Java>>正文


Java BusySpinWaitStrategy类代码示例

本文整理汇总了Java中com.lmax.disruptor.BusySpinWaitStrategy的典型用法代码示例。如果您正苦于以下问题:Java BusySpinWaitStrategy类的具体用法?Java BusySpinWaitStrategy怎么用?Java BusySpinWaitStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BusySpinWaitStrategy类属于com.lmax.disruptor包,在下文中一共展示了BusySpinWaitStrategy类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
@Setup
public void setup() {
    executor = Executors.newSingleThreadExecutor();
    disruptor = new Disruptor<LongEvent>(LongEvent.EVENT_FACTORY, executor, new SingleThreadedClaimStrategy(Run.QUEUE_SIZE), new BusySpinWaitStrategy());

    eventCount = new AtomicInteger();

    handler = (event, sequence, endOfBatch) -> {
        if(Run.LONGVAL == event.getValue()) {
            eventCount.incrementAndGet();
        } else {
            throw new RuntimeException("Failed.");
        }
    };

    disruptor.handleEventsWith(handler);

    ringBuffer = disruptor.start();
}
 
开发者ID:conversant,项目名称:disruptor_benchmark,代码行数:20,代码来源:LMAXDisruptorPushPullBenchmark.java

示例2: setup

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
@Setup
public void setup() {
    executor = Executors.newFixedThreadPool(Run.NTHREAD);
    disruptor = new Disruptor<LongEvent>(LongEvent.EVENT_FACTORY, executor, new MultiThreadedClaimStrategy(Run.QUEUE_SIZE), new BusySpinWaitStrategy());

    eventCount = new AtomicInteger();

    handler = (event, sequence, endOfBatch) -> {
        if(Run.LONGVAL == event.getValue()) {
            eventCount.incrementAndGet();
        } else {
            throw new RuntimeException("Failed.");
        }
    };

    disruptor.handleEventsWith(handler);

    ringBuffer = disruptor.start();
}
 
开发者ID:conversant,项目名称:disruptor_benchmark,代码行数:20,代码来源:LMAXDisruptorBenchmark.java

示例3: configure

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
@Override
protected void configure() {
    switch (config.getWaitStrategyEnum()) {
    // A low-cpu usage Disruptor configuration for using in local/test environments
    case LOW_CPU:
         bind(WaitStrategy.class).annotatedWith(Names.named("PersistenceStrategy")).to(BlockingWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("ReplyStrategy")).to(BlockingWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("RetryStrategy")).to(BlockingWaitStrategy.class);
         break;
    // The default high-cpu usage Disruptor configuration for getting high throughput on production environments
    case HIGH_THROUGHPUT:
    default:
         bind(WaitStrategy.class).annotatedWith(Names.named("PersistenceStrategy")).to(BusySpinWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("ReplyStrategy")).to(BusySpinWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("RetryStrategy")).to(YieldingWaitStrategy.class);
         break;
    }
    bind(RequestProcessor.class).to(RequestProcessorImpl.class).in(Singleton.class);
    bind(PersistenceProcessor.class).to(PersistenceProcessorImpl.class).in(Singleton.class);
    bind(ReplyProcessor.class).to(ReplyProcessorImpl.class).in(Singleton.class);
    bind(RetryProcessor.class).to(RetryProcessorImpl.class).in(Singleton.class);

}
 
开发者ID:apache,项目名称:incubator-omid,代码行数:24,代码来源:DisruptorModule.java

示例4: open

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
/**
 * Start dispatching events
 * 
 * @return a Future that asyncrhonously notifies an observer when this EventReactor is ready
 */
@SuppressWarnings("unchecked")
public CompletableFuture<? extends EventReactor<T>> open() {
  if (isRunning.compareAndSet(false, true)) {
    CompletableFuture<EventReactor<T>> future = new CompletableFuture<>();
    this.disruptor =
        new Disruptor<>(EVENT_FACTORY, ringSize, threadFactory, ProducerType.MULTI,
            new BusySpinWaitStrategy());
    this.disruptor.handleEventsWith(this::handleEvent);
    this.ringBuffer = disruptor.start();

    // Starts a timer thread
    this.timer = new Timer();
    future.complete(this);
    return future;
  } else {
    return CompletableFuture.completedFuture(this);
  }
}
 
开发者ID:FIXTradingCommunity,项目名称:silverflash,代码行数:24,代码来源:EventReactor.java

示例5: main

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
		long beginTime=System.currentTimeMillis();
		
		int bufferSize=1024;
		ExecutorService executor=Executors.newFixedThreadPool(4);
		//������캯�����������������˽�����2��demo֮��Ϳ��¾������ˣ���������~
		Disruptor<TradeTransaction> disruptor=new Disruptor<TradeTransaction>(new EventFactory<TradeTransaction>() {
			@Override
			public TradeTransaction newInstance() {
				return new TradeTransaction();
			}
		}, bufferSize, executor, ProducerType.SINGLE, new BusySpinWaitStrategy());
		
		//ʹ��disruptor������������C1,C2
		EventHandlerGroup<TradeTransaction> handlerGroup=disruptor.handleEventsWith(new TradeTransactionVasConsumer(),new TradeTransactionInDBHandler());
		
		TradeTransactionJMSNotifyHandler jmsConsumer=new TradeTransactionJMSNotifyHandler();
		//������C1,C2����֮��ִ��JMS��Ϣ���Ͳ��� Ҳ���������ߵ�C3
		handlerGroup.then(jmsConsumer);
		
		
		disruptor.start();//����
		CountDownLatch latch=new CountDownLatch(1);
		//������׼��
		executor.submit(new TradeTransactionPublisher(latch, disruptor));
		latch.await();//�ȴ�����������.
		disruptor.shutdown();
		executor.shutdown();
		
		System.out.println("�ܺ�ʱ:"+(System.currentTimeMillis()-beginTime));
//		long tt= System.currentTimeMillis();
//		for (int i = 0; i < 1000; i++) {
//			int j=i;
//		}
//		System.out.println("�ܺ�ʱ:"+(System.currentTimeMillis()-tt));
		
	}
 
开发者ID:wujh88,项目名称:disruptorDemo,代码行数:38,代码来源:Demo3.java

示例6: start

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void start() {
  if (isRunning.compareAndSet(false, true)) {
    this.disruptor =
        new Disruptor<>(BufferEvent.EVENT_FACTORY, ringSize, threadFactory, ProducerType.SINGLE,
            new BusySpinWaitStrategy());
    this.disruptor.handleEventsWith(this::handleEvent);
    this.ringBuffer = disruptor.start();
  }
}
 
开发者ID:FIXTradingCommunity,项目名称:silverflash,代码行数:11,代码来源:MessageBuffer.java

示例7: open

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
@Override
public CompletableFuture<? extends Service> open() {
  if (isRunning.compareAndSet(false, true)) {
    this.disruptor = new Disruptor<>(BufferEvent.EVENT_FACTORY, ringSize, threadFactory,
        ProducerType.SINGLE, new BusySpinWaitStrategy());
    this.disruptor.handleEventsWith(this::onEvent);
    this.ringBuffer = disruptor.start();
  }
  return CompletableFuture.completedFuture(this);
}
 
开发者ID:FIXTradingCommunity,项目名称:silverflash,代码行数:11,代码来源:BufferedTransportConsumer.java

示例8: test_All_WaitStrategies

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
@Test
public void test_All_WaitStrategies() {
	assertTrue(WaitStrategyType.BLOCKING.instance() instanceof BlockingWaitStrategy);
	assertTrue(WaitStrategyType.BUSY_SPIN.instance() instanceof BusySpinWaitStrategy);
	assertTrue(WaitStrategyType.LITE_BLOCKING.instance() instanceof LiteBlockingWaitStrategy);
	assertTrue(WaitStrategyType.SLEEPING_WAIT.instance() instanceof SleepingWaitStrategy);
	assertTrue(WaitStrategyType.YIELDING.instance() instanceof YieldingWaitStrategy);
}
 
开发者ID:anair-it,项目名称:disruptor-spring-manager,代码行数:9,代码来源:WaitStrategyTypeTest.java

示例9: createFromType

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
public static WaitStrategy createFromType(String name) {
    if ("BusySpin".equalsIgnoreCase(name)) {
        return new BusySpinWaitStrategy();
    } else if ("Blocking".equalsIgnoreCase(name)) {
        return new BlockingWaitStrategy();
    } else if ("Yielding".equalsIgnoreCase(name)) {
        return new YieldingWaitStrategy();
    } else if ("Sleeping".equalsIgnoreCase(name)) {
        return new SleepingWaitStrategy();
    } else {
        throw new IllegalArgumentException("Invalid or unsupported wait strategy type '" + name + "'");
    }
}
 
开发者ID:trautonen,项目名称:logback-ext,代码行数:14,代码来源:WaitStrategyFactory.java

示例10: setup

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
@Setup
public void setup()
{
    if (opWorkRatio < 0)
        throw new IllegalStateException();

    String[] opSleepArgs = opSleep.split("/");
    opSleepChance = Float.parseFloat(opSleepArgs[0]);
    opSleepNanos = Long.parseLong(opSleepArgs[1]) * 1000L;
    opWorkTokens = (int) Math.ceil(opWork * opWorkRatio * (1d / executorChainLength));

    String[] taskArgs = tasks.split(":");
    int concurrentRequests = (int) (threads * Double.parseDouble(taskArgs[0]));
    int maxTasksQueued = (int) (threads * Double.parseDouble(taskArgs[1]));
    final InjectorPlus injector = new InjectorPlus("");
    exec = new ExecutorPlus[executorChainLength];
    workGate = new Semaphore(concurrentRequests, false);
    for (int i = 0 ; i < exec.length ; i++)
    {
        switch (ExecutorType.valueOf(type))
        {
            case INJECTOR:
                exec[i] = injector.newExecutor(threads, maxTasksQueued);
                break;
            case JDK:
                exec[i] = new BlockingThreadPoolExecutor(threads, maxTasksQueued);
                break;
            case FJP:
                exec[i] = new BlockingForkJoinPool(threads, maxTasksQueued);
                break;
            case DISRUPTOR_SPIN:
                exec[i] = new DisruptorExecutor(threads, maxTasksQueued, new BusySpinWaitStrategy());
                break;
            case DISRUPTOR_BLOCK:
                exec[i] = new DisruptorExecutor(threads, maxTasksQueued, new BlockingWaitStrategy());
                break;
        }
    }
}
 
开发者ID:belliottsmith,项目名称:injector,代码行数:40,代码来源:ExecutorBenchmark.java

示例11: testAverageLatency

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
@Test
public void testAverageLatency() throws InterruptedException, ExecutionException{
	start = 0;
	end = 0;
	diff = 0;
	
	final ExecutorService es = Executors.newCachedThreadPool();

       // The factory for the event
       LongEventFactory factory = new LongEventFactory();

       // Specify the size of the ring buffer, must be power of 2.
       int bufferSize = 1024;

       // Construct the Disruptor
       Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(factory, bufferSize, es, ProducerType.SINGLE, new BusySpinWaitStrategy());

       // Connect the handler
       disruptor.handleEventsWith(new LongEventHandler());

  

       // Get the ring buffer from the Disruptor to be used for publishing.
       RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer();

       LongEventProducer prod = new LongEventProducer(ringBuffer);

       ByteBuffer bb = ByteBuffer.allocate(8);
       
	
	final Runnable producer = new Runnable(){

		public void run() {
			start = System.nanoTime();
			 bb.putLong(0, 1);
	         prod.onData(bb);
		}
		
	};
	
	 // Start the Disruptor, starts all threads running
       disruptor.start();
        Thread.sleep(1000);
	
	int size = 1000000;
	float percentageError = 0.05f;
	
	for (int i=0;i<size;i++){
		es.submit(producer);
		while(!eventRecieved){
			Thread.sleep(100);
		}
		eventRecieved = false;
	}
	
	double sum = 0;
	for (Long r : results){
		sum = r + sum;
	}
	
	long min = Collections.min(results);
	System.out.println("min nano: "+min);
	long max = Collections.max(results);
	System.out.println("max nano: "+max);
	System.out.println("results: "+results);
	System.out.println("average nano, minus anomalies: "+((sum-max-min)/(double)(results.size()-2)));
	System.out.println("average nano, minus anomalies: "+averageNanoMinusAnomalies(results,(int)(size*percentageError)));
	assertTrue(((sum-max-min)/(double)(results.size()-2))<13000);

}
 
开发者ID:aranhakki,项目名称:experimental-performance,代码行数:71,代码来源:DisruptorLatencyTest.java

示例12: testLatency

import com.lmax.disruptor.BusySpinWaitStrategy; //导入依赖的package包/类
@Test
public void testLatency() throws InterruptedException, ExecutionException{
	
	start = 0;
	end = 0;
	diff = 0;
	
	final ExecutorService es = Executors.newFixedThreadPool(2);
	
       // The factory for the event
       LongEventFactory factory = new LongEventFactory();

       // Specify the size of the ring buffer, must be power of 2.
       int bufferSize = 1024;

       // Construct the Disruptor
       Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(factory, bufferSize, es, ProducerType.SINGLE, new BusySpinWaitStrategy());

       // Connect the handler
       disruptor.handleEventsWith(new LongEventHandler());

  

       // Get the ring buffer from the Disruptor to be used for publishing.
       RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer();

       LongEventProducer prod = new LongEventProducer(ringBuffer);

       ByteBuffer bb = ByteBuffer.allocate(8);
	
	final Runnable producer = new Runnable(){

		public void run() {
			
			start = System.nanoTime();
			 bb.putLong(0, 1);
	         prod.onData(bb);
		}
		
	};
	
	 // Start the Disruptor, starts all threads running
       disruptor.start();
       
       Thread.sleep(1000);
       
	es.submit(producer);
	
	Thread.sleep(1000);
	
	long nano = diff;
	System.out.println("nano: "+nano);
	System.out.println("micro: "+(nano/1000));
	assertTrue((nano/1000)<100);
}
 
开发者ID:aranhakki,项目名称:experimental-performance,代码行数:56,代码来源:DisruptorLatencyTest.java


注:本文中的com.lmax.disruptor.BusySpinWaitStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。