通过 iPhone 从单一来源进行多个下载线程
我在从一台服务器下载 5 个不同的文件时遇到问题。是否可以通过 5 个单独的线程从该服务器下载所有 5 个文件?如果是,这比通过单线程依次下载每个文件是否有效?
I have a problem of downloading 5 different files from a single server. Is that possible to download all 5 files from that server over 5 individual threads ? If yes, is that efficient than downloading each file one after another via single thread ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过单独的线程下载文件总是更有效。如果您通过主线程下载它们,这只会阻塞主线程,并且您的应用程序在下载过程中会冻结一会儿。我建议,如果您要下载大量文件,请查看 MBProgressHUD 库,这是一个非常好的向用户传达下载进度的方式。
It is always more efficient to download files via separate threads. If you download them via the main thread, this will simply block the main thread and it will appear that your app has frozen for a moment while the downloads are taking place. I would suggest that if you are downloading a large number of files, look into the MBProgressHUD library which is an excellent way of communicating the downloads' progress to your users.
假设您此时正在从辅助线程下载:
是的。 5 个并发下载就可以了,并且最终可以减少完成所有 5 个请求所需的时间(实际上)。但是,您应该将并发下载数量保持在相对较低的水平 - 不要尝试同时运行 30 个,而是创建一个队列。
确定下载的优先级也很好,并在需要以更高优先级下载某些内容时添加暂停。
assuming you're downloading from secondary threads at this time:
yes. 5 concurrent downloads is fine, and can ultimately decrease the time it takes to complete all 5 requests (in practice). however, you should keep the number of concurrent downloads relatively low - don't try to run 30 at the same time, but create a queue.
it's also good to prioritize your downloads, and add suspension for times when you need something downloaded at a higher priority.