WAS4下载文件问题

cbhyk 2003-08-22 12:41:47
模拟被下载文件download.jsp:
<%
response.reset();
byte[] data = new byte[1024 * 1024 * 2];
response.setContentType("application/msdownload");
response.setContentLength(data.length);
java.io.OutputStream os = response.getOutputStream();
os.write(data);
%>

模拟下载程序SlowDownload.java:
package test;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
public class SlowDownload
{
public static void main(String[] args)
{
try
{
int speed = 3000; //下载速度3KB每秒
URL url = new URL("http://localhost/download.jsp");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
System.out.println("content length:" + conn.getContentLength());
InputStream in = conn.getInputStream();
System.out.println("InputStream available:" + in.available());
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
int bytes = 0;
int total = 0;
int count = 0;
long startTime = System.currentTimeMillis();
byte[] buf = new byte[speed / 10];
while((bytes = in.read(buf)) != -1)
{
total += bytes;
count ++;
if(count % 10 == 0)
{
now.setTime(System.currentTimeMillis());
System.out.println(sdf.format(now) + "\t" + total + "\t" + in.available());
}
Thread.sleep(100);
}
now.setTime(System.currentTimeMillis());
System.out.println(sdf.format(now) + "\t" + total);
conn.disconnect();
}
catch(Exception e)
{
e.printStackTrace();
System.exit(2);
}
}
}

当下载速度为3000时,下载到270K左右的时候出错:
java.net.SocketException: Connection reset by peer: JVM_recv in socket input stream read
at java.net.SocketInputStream.socketRead(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:86)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:186)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:225)
at java.io.BufferedInputStream.read(BufferedInputStream.java:280)
at java.io.FilterInputStream.read(FilterInputStream.java:114)
at java.io.PushbackInputStream.read(PushbackInputStream.java:164)
at sun.net.www.MeteredStream.read(MeteredStream.java:68)
at java.io.FilterInputStream.read(FilterInputStream.java:93)
at test.SlowDownload.main(SlowDownload.java:40)

当下载速度为2000时,下载到160K左右的时候出错
当下载速度为1000时,下载到90K左右的时候出错
当下载速度为5000时,下载成功完成
...全文
42 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cbhyk 2003-08-27
  • 打赏
  • 举报
回复
我们也试出来是HTTP服务器缓冲区过小的问题了,但我们的WebSphere版本是4.0.5 + ptf50246.04。目前已调大缓冲区,正在做测试。
Ryan76 2003-08-26
  • 打赏
  • 举报
回复
同意楼上的
ewingchen 2003-08-26
  • 打赏
  • 举报
回复
这是WAS4早期版本的bug,由于WAS4对HTTP服务器设置的缓冲区过小所致

建议将WAS4升级到4.05以后版本.
cbhyk 2003-08-26
  • 打赏
  • 举报
回复
up
cbhyk 2003-08-25
  • 打赏
  • 举报
回复
我试了一下,通过9080端口下载就没有问题,应该就是HTTP服务器的问题了,但目前的HTTP服务器设置是:
Timeout 300
KeepAlive On
MaxKeepAliveRequests 500
KeepAliveTimeout 15
MaxRequestsPerChild 0
同样下载不了,不知怎样设置才行?
Ryan76 2003-08-23
  • 打赏
  • 举报
回复
我想是你的Http服务器的配置问题
Timeout 300


KeepAlive On


MaxKeepAliveRequests 100

KeepAliveTimeout 15


MaxRequestsPerChild 0

2,633

社区成员

发帖
与我相关
我的任务
社区描述
WebSphere 是 IBM 的软件平台。它包含了编写、运行和监视全天候的工业强度的随需应变 Web 应用程序和跨平台、跨产品解决方案所需要的整个中间件基础设施,如服务器、服务和工具。
社区管理员
  • WebSphere社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧