最近做一个下载的模块。其中有个暂停的功能。
我实现的时候,是通过在while()循环的时候通过判断状态break掉的,但是在关闭流的时候出了问题
下边是伪代码InputStream is = HttpResponse.getEntity().getContent();while ((len = is.read(bs)) != -1) {
write();
if(cancle){
LogTag.showTAG_e("log", "download break");
break;
}}后边就是关闭流的代码了long time = 0;
time = System.currentTimeMillis();
is.close();
time = System.currentTimeMillis() - time;
LogTag.showTAG_e("log", "close the inputstream cost====="+time);下边是日志========download break=============
========close the inputstream cost=====262014=============初步测试是以为输入流还没有读完就关闭,才导致耗时过长!
求解:这是什么导致的?有什么解决方案?
因为是做的手机客户端的功能,虽然最后实在没办法在新开通的线程中关闭了,但是感觉不靠谱!
我实现的时候,是通过在while()循环的时候通过判断状态break掉的,但是在关闭流的时候出了问题
下边是伪代码InputStream is = HttpResponse.getEntity().getContent();while ((len = is.read(bs)) != -1) {
write();
if(cancle){
LogTag.showTAG_e("log", "download break");
break;
}}后边就是关闭流的代码了long time = 0;
time = System.currentTimeMillis();
is.close();
time = System.currentTimeMillis() - time;
LogTag.showTAG_e("log", "close the inputstream cost====="+time);下边是日志========download break=============
========close the inputstream cost=====262014=============初步测试是以为输入流还没有读完就关闭,才导致耗时过长!
求解:这是什么导致的?有什么解决方案?
因为是做的手机客户端的功能,虽然最后实在没办法在新开通的线程中关闭了,但是感觉不靠谱!
楼主可以换成WiFi试试,如果还慢,那应该是服务器应答缓慢的原因。