在 LMAX-Exchange/Disruptor 3.4.3 中,RingBuffer在其实际字段之前放置了 7 个长填充字段(通过 extends RingBufferPad )
abstract class RingBufferPad
{
protected long p1, p2, p3, p4, p5, p6, p7;
}
并在最后放置另外 7 个长填充字段以避免错误共享
public final class RingBuffer<E> extends RingBufferFields<E> implements Cursored, EventSequencer<E>, EventSink<E>
{
public static final long INITIAL_CURSOR_VALUE = Sequence.INITIAL_VALUE;
protected long p1, p2, p3, p4, p5, p6, p7;
问题是为什么要放置 7 个长填充字段,而不是Mechanical Sympathy - False Sharing中描述的 6 个字段。
public final static class VolatileLong
{
public volatile long value = 0L;
public long p1, p2, p3, p4, p5, p6; // comment out
}