使用Java批量下载图像的好方法 [英] A good way to bulk download images over http with Java

查看:107
本文介绍了使用Java批量下载图像的好方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个网络应用程序,需要通过http从合作伙伴网站导入10-20张图片。如果我有一个表示我想要下载的网址的字符串列表,是否有人建议如何尽快下载它们?

We have a web application that needs to import 10-20 images from a partner site via http. If I have a list of strings that represent the urls I want to download does anybody have a suggestion for how to download them as fast as possible?

我可以放置它们在for循环中但是如果有一种简单的方法来并行化它,那么对最终用户来说可能是好的。我想避免使用直接的Java线程,虽然执行器框架可能是个好主意。

I could just put them in a for loop but if there is a simple way to parallelize this it would be probably be good for the end user. I would like to avoid using straight Java threads, although the executor framework might be a good idea.

任何想法?

推荐答案

Executor框架完全符合您的要求。特别是ExecutorCompletionService。使用此功能,您将能够以任何顺序快速提交请求。然后,您将完成它们的完整检索(与提交订单相反)。

The Executor framework is EXACTLY what you want. Specifically the ExecutorCompletionService. Using this, you'll be able to submit requests quickly and in any order. Then you'll retrieve them exactly as they completed (as opposed to submission order).

这篇关于使用Java批量下载图像的好方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆