zoukankan      html  css  js  c++  java
  • Disruptor Java版和.NET版的区别

    The main differences comes from the fact that .NET supports structs (value types), Java doesn't.

    In Java, every entry (or message) exchanged by the disruptor needs to inherit from a base class called AbstractEntry. This class exposes the Sequence number required by the disruptor to process the messages, it is basically a header for the message.

    In .NET we have replaced AbstractEntry by a generic struct: Entry<T>. An entry contains 2 fields: the sequence number and a field called data, used to store the message (of type T). Using this struct has several advantages:

    • the array in the RingBuffer is of type Entry<T>, when we need to access the Sequence number we don't have to dereference (Entry<T> is a struct so instances are directly nested in the array) and this improves cache spatial locality.
    • your message types do not need to implement or inherit from a base class, you can use POCOs.

    最主要的区别是.NET支持结构类型(结构类型是值类型),而Java不支持。

    在Java中,每一个被Disruptor交换的条目(或者消息)需要继承AbstractEntry基类。这个类提供了Disruptor处理消息时必须的序列号。它是消息头中最基本的信息。

    在.NET中用泛型结构Entry<T>代替了Java中的AbstractEntry,一个条目包含两个域:一个是序列号,另一个是数据域,用来存储消息(T类型)。用结构有如下几个优点:

    • RingBuffer中的数组是Entry<T>类型,当我们需要访问序列号时,不需要解引用,并且能够提高缓存空间的局部性。
    • 你的消息类型不需要实现或者继承基类,你可以使用POCOs.
  • 相关阅读:
    Confluence5.6.6安装和破解
    Redis 数据备份与恢复
    Linux Shell
    戴尔R720安装ESXI系统
    zbb20171223 vm12 Vmware虚拟机设置静态IP地址
    zbb20171221 bootstrap 模态窗口
    zbb20171221 thymeleaf 格式化工具 工具对象用法
    zbb20171221 thymeleaf 基本语法
    zbb20171221 thymeleaf th:each
    zbb20171215 maven pom 包命名搜索地址
  • 原文地址:https://www.cnblogs.com/ucos/p/3557522.html
Copyright © 2011-2022 走看看