Peter Penzov
Peter Penzov

Reputation: 1726

How to implement RingFiFoBuffer

I'm new to Java programming. I have several questions about how to implement RingFiFoBuffer:

  1. Can I store big XML files into this buffer? If yes how big?
  2. Can several threads insert/delete/fetch records from the RingBuffer simultaneously?
  3. How many records can I store?
  4. Is there any tutorial that I can see how to write the code.

I only found http://commons.apache.org/collections/apidocs/org/apache/commons/collections/buffer/CircularFifoBuffer.html

Upvotes: 0

Views: 490

Answers (2)

Peter Lawrey
Peter Lawrey

Reputation: 533870

Can I store big XML files into this buffer? If yes how big?

You are only limited by your disk space with memory mapped files.

Can several threads insert/delete/fetch records from the RingBuffer simultaneously?

That depends on your implementation. Usually ring buffers are shared between threads.

How many records can I store?

This is something you usually limit when you create the ring buffer so its up to you. Its usually sensible to keep these to a minimum as larger ring buffers can often be slower than tighter ring buffers. So the practical limit may depend on your application and the hardware used.

Is there any tutorial that I can see how to write the code.

The best example I know is the Disruptor library. Its pretty advanced but has better documentation than any I can think of. (Including libraries I have written ;)

http://code.google.com/p/disruptor/

Upvotes: 1

Robert
Robert

Reputation: 42799

Question 1 and 3: That is only limited by the memory you assign to the Java process that executes your program.

Qestion 2: Accessing a Collection like the referenced CircularFifoBuffer usually requires to "synchronize" them. The linked JavaDoc already contains the code for synchronizing it:

Buffer fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer());

Upvotes: 1

Related Questions