Class DoubleBuffer<T>

java.lang.Object
com.persequor.extension.common.DoubleBuffer<T>
Type Parameters:
T - type of the buffer

public class DoubleBuffer<T> extends Object
Implementation of the double buffer pattern. Allows splitting reading and writing operations on the continuously modified buffer. The write operation is blocking ensuring the consistency of the current buffer whereas the read operation is only blocking for the time of swapping the buffer. If it is important that the reading operation is not running in parallel, it must be a responsibility of the reader to block the execution.
  • Constructor Details

    • DoubleBuffer

      public DoubleBuffer(Supplier<T> bufferProvider)
  • Method Details

    • write

      public void write(Consumer<T> writer)
      The write operation is blocking ensuring the consistency of the current buffer.
      Parameters:
      writer - writing to the buffer
    • read

      public T read()
      The read operation is only blocking for the time of swapping the buffer.