b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

disruptor kafka?disruptor activemq?disruptor入门

电脑杂谈  发布时间:2016-08-06 22:01:17  来源:网络整理

你是否正在寻找关于disruptor的内容?让我把最完美的东西奉献给你:

disruptor_disruptor kafka_disruptor activemq

1.disruptor是什么?

disruptor是一个高性能的异步处理框架,或者可以认为是最快的消息框架(轻量的JMS),也可以认为是一个观察者模式的实现,或者事件模式的实现,。

2.disruptor的原理

英文:

翻译:

3.实现例子

1)pojo类

/** * just think of a pojo * @author guolei * */ public final class ValueEvent { private long value; public long getValue() { return value; } public void setValue(final long value) { this.value = value; } public final static EventFactory<ValueEvent> EVENT_FACTORY = new EventFactory<ValueEvent>() { public ValueEvent newInstance() { return new ValueEvent(); } }; } 2)生产者 public class Producer implements Runnable { private RingBuffer<ValueEvent> ringBuffer = null; public Producer(RingBuffer<ValueEvent> rb) { ringBuffer = rb; } @Override public void run() { // Publishers claim events in sequence long sequence = ringBuffer.next(); ValueEvent event = ringBuffer.get(sequence); event.setValue(1234); // this could be more complex with multiple fields // make the event available to EventProcessors ringBuffer.publish(sequence); } } 3)消费者 public class ConsumeEventHandler implements EventHandler<ValueEvent>{ @Override public void onEvent(ValueEvent event, long sequence, boolean endOfBatch) throws Exception { // TODO Auto-generated method stub System.out.println("=================="+event.getValue()); } }

4)测试类

public class TestShow { private static final int BUFFER_SIZE = 16; private final RingBuffer<ValueEvent> ringBuffer = new RingBuffer<ValueEvent>( ValueEvent.EVENT_FACTORY, new SingleThreadedClaimStrategy(BUFFER_SIZE), new YieldingWaitStrategy()); private final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier(); private final ConsumeEventHandler handler = new ConsumeEventHandler(); private final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor(); private final BatchEventProcessor<ValueEvent> batchEventProcessor = new BatchEventProcessor<ValueEvent>( ringBuffer, sequenceBarrier, handler); public TestShow() { ringBuffer.setGatingSequences(batchEventProcessor.getSequence()); } public void consume() { EXECUTOR.submit(batchEventProcessor); } public void produce() { new Thread(new Producer(ringBuffer)).start(); } public static void main(String[] args) { TestShow test = new TestShow(); test.produce(); test.consume(); } }



以上就是关于disruptor的全部内容,相信你一定会非常满意。


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-14094-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 汉元帝
        汉元帝

        老马啊巴菲特他真的是靠股票发家的

      热点图片
      拼命载入中...