Java下载防洪
目前我有一个java下载器,可以下载.zip文件并解压缩它,但是主机有8mb的下载速度限制。因此,由于带宽问题,如果超过 10 人同时下载文件(大约 30MB),则会导致下载速度急剧下降,导致下载时间从 2 分钟缩短到 10 个小时。
下载代码
BufferedInputStream in = new BufferedInputStream(new java.net.URL(
"http://example.com/exampleJar.jar").openStream());
FileOutputStream fos = new FileOutputStream("exampleJar.jar");
BufferedOutputStream bout = new BufferedOutputStream(fos);
无论如何,这是我的 我想,也许有一种方法可以检查有多少人正在下载它,如果当前有 X 人正在下载,请切换到可以在链接数组中找到的不同链接。
currently I have a java downloader that downloads a .zip file and uncompresses it, however the host has an 8mb download speed limit. So due to bandwidth issues if more then 10 people are concurrently downloading the file (which is about 30MB) it causes the download speed to go down drastically, causing it to go from taking 2 minutes to 10 hours
Anyways, here's the downloading code
BufferedInputStream in = new BufferedInputStream(new java.net.URL(
"http://example.com/exampleJar.jar").openStream());
FileOutputStream fos = new FileOutputStream("exampleJar.jar");
BufferedOutputStream bout = new BufferedOutputStream(fos);
I'm thinking, perhaps a method to check how many people are downloading it, and if X amount of people are currently downloading, switch to a different link which could be found in an array of links.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该在服务器端而不是客户端完成
,具体取决于您使用的服务器类型,
如果超过您的预设值
发送http 302 http暂时移动,找到一种方法来计算当前正在运行的请求,并给出另一个下载URL
说
http://download2.example.com/exampleJar.jar
this should be done at the server side rather than client side
depending on what kind of server u use, find a way to count currently running requests
if more than your preset value
send http 302 http temporarily moved, and give another download URL
say
http://download2.example.com/exampleJar.jar