排队多个下载,寻找生产者消费者 API
我有一个应用程序(一个 servlet,但这不是很重要),它下载一组文件并解析它们以提取信息。到目前为止,我循环执行了这些操作: - 在互联网上获取新文件 - 分析它。
多线程下载管理器似乎是解决此问题的更好方法,我想以尽可能最快的方式实现它。
某些下载依赖于其他下载(因此,此集合是部分订购的)。
多线程编程很困难,如果我能找到一个 API 来做到这一点,我会很高兴。我需要将一组文件(已排序)放入队列中,并获取第一组完全下载的文件。
你知道我可以用什么库来实现这一目标吗?
问候, 史蒂芬
I have an application (a servlet, but that's not very important) that downloads a set of files and parse them to extract information. Up to now, I did those operations in a loop :
- fetching new file on the Internet
- analyzing it.
A multi-threaded download-manager seems a better solution for this problem and I would like to implement it in the fastest way possible.
Some of the downloads are dependant from others (so, this set is partially ordered).
Mutli-threaded programming is hard and if I could find an API to do that I would be quite happy. I need to put a group of files (ordered) in a queue and get the first group of files that is completely downloaded.
Do you know of any library I could use to achieve that ?
Regards,
Stéphane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行以下操作:
如果每次下载的速度不同,您可能必须使用不同类型的队列。我相信 BlockingQueue 是先进先出的。
您可能需要考虑使用 PriorityBlockingQueue,它将根据下载对象的 Comparable 方法对它们进行排序。请参阅API 了解更多详细信息。
希望这有帮助。
You could do something like:
You may have to use a different kind of queue if the speed of each download is not the same. BlockingQueue is first in first out I believe.
You may want to look into using a PriorityBlockingQueue which will order the Download objects according to their Comparable method. See the API here for more details.
Hope this helps.