<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    I want to fly higher
    programming Explorer
    posts - 114,comments - 263,trackbacks - 0
    package com.mavsplus.example.disruptor;

    import java.nio.ByteBuffer;
    import java.util.concurrent.Executor;
    import java.util.concurrent.Executors;

    import com.lmax.disruptor.RingBuffer;
    import com.lmax.disruptor.dsl.Disruptor;

    /**
     * Distrupor Getting Started
     * 
     * <a
     * href="https://github.com/LMAX-Exchange/disruptor/wiki/Getting-Started"></a>
     * 
     * @author landon
     * @since 1.8.0_25
     
    */
    public class DisruptorExample {

        /**
         * the Event that will carry the data
         
    */
        public static class LongEvent {

            private long value;

            public void set(long value) {
                this.value = value;
            }

            @Override
            public String toString() {
                return "LongEvent [value=" + value + "]";
            }
        }

        public static void main(String[] args) throws Exception {
            // usingJava8();
            usingJava8Another();
        }

        // Using Java8
        @SuppressWarnings("unchecked")
        private static void usingJava8() throws InterruptedException {
            // Executor that will be used to construct new threads for consumers
            Executor executor = Executors.newCachedThreadPool();

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

            // Construct the Disruptor
            Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent::new, bufferSize, executor);
            // Connect the handler
            disruptor.handleEventsWith((event, sequence, endOfBatch) -> System.out.println("Event: " + event));
            // Start the Disruptor, starts all threads running
            disruptor.start();

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

            ByteBuffer bb = ByteBuffer.allocate(8);

            for (long l = 0true; l++) {
                bb.putLong(0, l);

                ringBuffer.publishEvent((event, sequence) -> event.set(bb.getLong(0)));

                Thread.sleep(1000);
            }
        }

        /**
         * <code>
         ByteBuffer bb = ByteBuffer.allocate(8);
            for (long l = 0; true; l++)
            {
                bb.putLong(0, l);
                ringBuffer.publishEvent((event, sequence) -> event.set(bb.getLong(0)));
                Thread.sleep(1000);
            }
            </code> This would create a capturing lambda, meaning that it would need
         * to instantiate an object to hold the ByteBuffer bb variable as it passes
         * the lambda through to the publishEvent() call. This will create
         * additional (unnecessary) garbage, so the call that passes the argument
         * through to the lambda should be preferred if low GC pressure is a
         * requirement.Give that method references can be used instead of anonymous
         * lamdbas it is possible to rewrite the example in this fashion.
         * 
         
    */
        @SuppressWarnings("unchecked")
        private static void usingJava8Another() throws InterruptedException {

            // Executor that will be used to construct new threads for consumers
            Executor executor = Executors.newCachedThreadPool();

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

            // Construct the Disruptor
            Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent::new, bufferSize, executor);
            // Connect the handler
            disruptor.handleEventsWith(DisruptorExample::handleEvent);
            // Start the Disruptor, starts all threads running
            disruptor.start();

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

            ByteBuffer bb = ByteBuffer.allocate(8);

            for (long l = 0true; l++) {
                bb.putLong(0, l);

                ringBuffer.publishEvent(DisruptorExample::translate, bb);

                Thread.sleep(1000);
            }
        }

        public static void handleEvent(LongEvent event, long sequence, boolean endOfBatch) {
            System.out.println(event);
        }

        public static void translate(LongEvent event, long sequence, ByteBuffer buffer) {
            event.set(buffer.getLong(0));
        }
    }
    posted on 2015-06-15 18:34 landon 閱讀(3938) 評論(0)  編輯  收藏 所屬分類: ProgramServerFramework
    主站蜘蛛池模板: 91在线亚洲综合在线| 看Aⅴ免费毛片手机播放| 免费黄色小视频网站| 黄色一级视频免费| 亚洲av无码专区在线播放 | a级日本高清免费看| 亚洲免费电影网站| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 亚洲综合精品香蕉久久网97| 成人黄动漫画免费网站视频 | 在线日韩av永久免费观看| 中文无码成人免费视频在线观看 | 九九精品国产亚洲AV日韩| 亚洲AV一宅男色影视| 永久黄网站色视频免费观看| 国产免费一区二区三区不卡| 亚洲精品无码成人片久久不卡 | 亚洲首页在线观看| 亚洲狠狠爱综合影院婷婷| 久久精品免费全国观看国产| 久青草视频在线观看免费| 亚洲精品V天堂中文字幕| 亚洲日本在线观看| 国产91精品一区二区麻豆亚洲| 成人免费一级毛片在线播放视频| 黄视频在线观看免费| 亚洲AV成人片无码网站| 在线观看亚洲人成网站| 亚洲熟妇av一区二区三区| 日本成人在线免费观看| 57PAO成人国产永久免费视频| 免费国产污网站在线观看| 免费在线观看亚洲| 亚洲精品理论电影在线观看| 亚洲毛片在线免费观看| 久久精品国产亚洲AV网站| 国产亚洲精品精品国产亚洲综合| 国产成人免费a在线视频app| 久久WWW免费人成人片| 久久WWW免费人成一看片| 日韩成人免费视频|