BufferedIterator 实现
有人知道开源 BufferedIterator 吗,其中接下来的 N 个元素是在后台线程上急切获取的? 这是 来自 TechRepublic 文章,但我认为它尚未经过彻底测试。
迭代器.buffer( Iterator toBuffer, int bufferSize) 将是 Guava 的一个很好的补充,有没有考虑过?
Does someone know of an open source BufferedIterator, where the next N elements are eagerly fetched on a background thread?
Here is an implementation from a TechRepublic article, but I assume it has not been thoroughly tested.
Iterators.buffer(Iterator toBuffer, int bufferSize) would be a nice addition to Guava, has that been considered?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
链接的实现似乎是为 Java 4 编写的,可以使用 guava 和 java.util.concurrent 进行一些简化:
注意:上述实现不会尝试处理源迭代器中的异常(如果抛出一个,插入器任务将突然终止,使调用线程陷入死锁。)
The linked implementation appears to have been written for Java 4 and can be simplified a little using guava and
java.util.concurrent
:Note: the above implementation makes no attempt to handle exceptions in the source iterator (if one is thrown, the inserter task will terminate abruptly, leaving the calling thread deadlocked.)