相关疑难解决方法(0)

Android - HttpUrlConnection没有关闭.最终导致SocketException

我在运行Jellybean(4.1 - 4.3)的设备中遇到HttpUrlConnection的一些问题,其中连接未关闭并且在执行多次后导致SocketException"Too many open files".

我打算调用HttpUrlConnection.disconnect()并关闭finally块中的所有Inputstream,Outputstream,Reader和Writers.

转到adb shell并执行netstat显示应用程序创建的所有连接都处于CLOSE_WAIT状态.

InputStream inputStream = httpUrlConnection.getInputStream();

// After calling inputStream.read() then the problem occurs. I think the 
// inputstream doesn't get closed even after calling close in a finally block. 
// The InputStream is a ChunkedInputStream if that helps.
Run Code Online (Sandbox Code Playgroud)

我尝试过在2.3.3,4.0.3和4.4上运行的其他设备并没有遇到这个问题.

还有其他方法可以手动关闭连接吗?

java android httpurlconnection

9
推荐指数
1
解决办法
5450
查看次数

标签 统计

android ×1

httpurlconnection ×1

java ×1