Android学习记录(十一) 填坑之inputStream close关闭慢的处理。
来源:互联网 发布:asp.net windows认证 编辑:程序博客网 时间:2024/05/29 10:13
先上stackoverflow的解决方案,再来细说:
http://stackoverflow.com/questions/18471088/inputstream-close-takes-too-long-to-finish-time-relative-to-size-of-file
当使用http get的文件巨大时,你会发现stream.close()的方法会特别的慢。
为什么慢,文章中提到:
"Note that this class NEVER closes the underlying stream, even when close gets called. Instead, it will read until the "end" of its limit on close, which allows for the seamless execution of subsequent HTTP 1.1 requests, while not requiring the client to remember to read the entire contents of the response."
这样就导致遇到大文件,如果你有下载暂停的动作,那么你的close处理会非常的耗时。
目前个人越到下面的两个问题:
1.原先的写法close的动作放在try{}内进行,如果你后续有http close(如断网的操作)会走进
catch (IOException e) 的流程中,而正常情况下,该流程是需要处理io读写失败的。会导致逻辑处理更加复杂。
2.thread长期无法释放,开销巨大。
目前的解决办法:
finally { if ((in != null) && (httpGet!=null)){ try { httpGet.abort(); in.close(); } catch (IOException e) { e.printStackTrace(); } }
0 0
- Android学习记录(十一) 填坑之inputStream close关闭慢的处理。
- Android学习记录(十三) http之digest鉴权之填坑6.0。
- android assets InputStream 慢?
- Android学习记录(十八)-url转义继续填坑之旅
- Android学习记录(二十一)-crash保护处理
- 跟着Android官方培训课程学习,挖坑填坑记录
- Android WebView填坑记录
- Android WebView填坑记录
- Android WebView填坑记录
- 输入流 inputStream close()后,它所在的Socket也将关闭
- oracle学习记录之十一
- Android学习记录(二十五)-记录一下Android cursor onPause中close的异常。
- 记录一些android路上填的坑踩的水
- Android学习记录(十六) recyclerview 滑动慢的问题。
- 【Android填坑系列】ScrollView嵌套GridView的处理
- Webpack学习笔记与填坑记录
- Java:浅谈InputStream的close方法
- socket关闭之close()和shutdown()的差异
- 在Chrome(49.0.2623.87)版本下通过JS改变select的选项时,要先清空之前的option元素的selected属性的问题
- iOS的内存管理
- Android ScrollView的基本使用及原理。
- JDBC连接MySQL产生java.lang.ClassNotFoundException异常
- Linux设备模型(2)_Kobject
- Android学习记录(十一) 填坑之inputStream close关闭慢的处理。
- PLSQL Developer使用技巧
- Vim:黑客帝国屏保
- 命名管道使用
- Android亮度调整解析
- 在Vim中玩俄罗斯方块
- Windows下游戏制作(1)---win32窗口创建(2)
- 高仿今日头条(2)
- 欢迎使用CSDN-markdown编辑器