如何实现RingFiFoBuffer
我是 Java 编程新手。我有几个关于如何实现 RingFiFoBuffer 的问题:
- 我可以将大型 XML 文件存储到此缓冲区中吗?如果有的话有多大?
- 多个线程可以同时从 RingBuffer 插入/删除/获取记录吗?
- 我可以存储多少条记录?
- 有没有教程可以让我看看如何编写代码。
I'm new to Java programming. I have several questions about how to implement RingFiFoBuffer:
- Can I store big XML files into this buffer? If yes how big?
- Can several threads insert/delete/fetch records from the RingBuffer simultaneously?
- How many records can I store?
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题 1 和 3:这仅受分配给执行程序的 Java 进程的内存的限制。
问题 2:访问像引用的 CircularFifoBuffer 这样的集合通常需要“同步”它们。链接的 JavaDoc 已包含用于同步它的代码:
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:
您仅受内存映射文件的磁盘空间的限制。
这取决于您的实施。通常环形缓冲区在线程之间共享。
这是您在创建环形缓冲区时通常会限制的内容,因此这取决于您。将这些值保持在最低限度通常是明智的,因为较大的环形缓冲区通常会比较小的环形缓冲区慢。因此,实际限制可能取决于您的应用程序和所使用的硬件。
我知道的最好的例子是 Disruptor 库。它相当先进,但拥有比我能想到的更好的文档。 (包括我编写的库;)
http://code.google.com/p/disruptor/
You are only limited by your disk space with memory mapped files.
That depends on your implementation. Usually ring buffers are shared between threads.
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.
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/