<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 閱讀(3940) 評論(0)  編輯  收藏 所屬分類: ProgramServerFramework
    主站蜘蛛池模板: 久久久久噜噜噜亚洲熟女综合| 亚洲?V无码成人精品区日韩| 国产V亚洲V天堂无码| 一个人看的www免费在线视频| 久青草国产免费观看| 四虎永久在线精品视频免费观看| 免费中文字幕不卡视频| 精品无码专区亚洲| 亚洲AV成人潮喷综合网| 人妻巨大乳hd免费看| 久久久精品国产亚洲成人满18免费网站 | 在线观看片免费人成视频无码| 人妻无码久久一区二区三区免费| 100000免费啪啪18免进| 亚洲av无码片区一区二区三区| 特级毛片A级毛片免费播放| 国产免费卡一卡三卡乱码| 男女啪啪免费体验区| 国产亚洲美日韩AV中文字幕无码成人 | 亚洲理论片在线观看| av大片在线无码免费| 亚洲毛片在线免费观看| 女人被男人躁的女爽免费视频| 亚洲人成人网站色www| 国产午夜不卡AV免费| 亚洲精品国产免费| 日韩免费a级在线观看| 丁香六月婷婷精品免费观看| 亚洲AV综合色区无码一区 | 亚洲五月综合网色九月色| 日韩精品免费电影| 香蕉国产在线观看免费| 亚洲国产女人aaa毛片在线| 最近免费中文字幕4| 狠狠躁狠狠爱免费视频无码| 亚洲va在线va天堂va不卡下载 | 337p日本欧洲亚洲大胆裸体艺术| 亚洲偷偷自拍高清| 啊v在线免费观看| 久久免费精彩视频| 无码一区二区三区亚洲人妻|