Solution to Android exception java.lang.illegalstateexception

Android exception details

For this exception, I encounter the following two situations: 1. Java.lang.illegalstateexception: no wrapped connection. 2. Java.lang.illegalstateexception: adapter is detached

reason:

1. A single thread can execute one request at a time. If multiple threads are used, connection timeout will occur when multiple requests are executed at the same time. 2. HTTPCONNECTION does not have the concept of connection pool. How many IOS will be established for how many requests. In case of huge access, the IO of the server may be exhausted. 3. It is usually because httpclient accesses different threads of a single instance or does not close the httpresponse of InputStream.

Solution: get httpclient thread safety

Pre resolution code:

Code after resolution:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>