如何实现RingFiFoBuffer

发布于 2025-01-04 10:03:51 字数 454 浏览 1 评论 0原文

我是 Java 编程新手。我有几个关于如何实现 RingFiFoBuffer 的问题:

  1. 我可以将大型 XML 文件存储到此缓冲区中吗?如果有的话有多大?
  2. 多个线程可以同时从 RingBuffer 插入/删除/获取记录吗?
  3. 我可以存储多少条记录?
  4. 有没有教程可以让我看看如何编写代码。

我只找到http://commons.apache。 org/collections/apidocs/org/apache/commons/collections/buffer/CircularFifoBuffer.html

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光礼记 2025-01-11 10:03:51

问题 1 和 3:这仅受分配给执行程序的 Java 进程的内存的限制。

问题 2:访问像引用的 CircularFifoBuffer 这样的集合通常需要“同步”它们。链接的 JavaDoc 已包含用于同步它的代码:

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

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());
辞取 2025-01-11 10:03:51

我可以将大的 XML 文件存储到此缓冲区中吗?如果有的话有多大?

您仅受内存映射文件的磁盘空间的限制。

多个线程可以同时从 RingBuffer 插入/删除/获取记录吗?

这取决于您的实施。通常环形缓冲区在线程之间共享。

我可以存储多少条记录?

这是您在创建环形缓冲区时通常会限制的内容,因此这取决于您。将这些值保持在最低限度通常是明智的,因为较大的环形缓冲区通常会比较小的环形缓冲区慢。因此,实际限制可能取决于您的应用程序和所使用的硬件。

有没有教程可以让我看到如何编写代码。

我知道的最好的例子是 Disruptor 库。它相当先进,但拥有比我能想到的更好的文档。 (包括我编写的库;)

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

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文