首页 > Web开发 > 详细

Disruptor Java版和.NET版的区别

时间:2014-02-21 01:05:50      阅读:270      评论:0      收藏:0      [点我收藏+]

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.

Disruptor Java版和.NET版的区别

原文:http://www.cnblogs.com/ucos/p/3557522.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!