Previously uploaded files times this exception did not care so much, this time the network bad always reported this anomaly, resulting in file upload failure, so deliberately explained, reported an unusual reason or a lot of, today only for my current encounter problems to record.
Background: Usually when the network is good, I open the thread upload and download no problem, the network is slow to come out this abnormal Recv failure:connection reset by Peer .
The cause of the exception is two points: 1, the network is very slow to cause the exception, 2, the thread repeatedly requests the network service caused by the exception, because the last enabled thread has not been disconnected, so the service has been present, causing the upload request again exception.
The thread that started writing is written like this:
New Thread (New Runnable () { @Override public void Run () { TODO auto-generated Method Stub try { File File = new file (FilePath); Uploadform (param, Filekey, file, File.getname (), Requesturl, Mcontext); } catch (IOException e) { TODO auto-generated Catch block E.printstacktrace (); } } }). Start (); |
This kind of writing is quite convenient, when the request is finished, the thread is automatically recycled, but if the request is not responding, the thread will always be there, so when we click on the second Upload request service, we will still report the exception, because the thread has been on the " Tao " and the other requests have no way to go. So change to:
if (mthread! = null) { Mthread.interrupt (); Mthread = null; } Mthread = new Thread (new Runnable () { @Override public void Run () { TODO auto-generated Method Stub try { File File = new file (FilePath); Uploadform (param, Filekey, file, File.getname (), Requesturl, Mcontext); } catch (IOException e) { TODO auto-generated Catch block E.printstacktrace (); } } }); Mthread.start (); |
After the change, the upload exception resolved!
In the changed code, we judge each thread request, guarantee the independence of each request, in the previous project also encountered this problem, then change into a socket for transmission is OK, the problem of the solution is diverse, I hope that the same problem you can be helpful!
This article is from the "Suck on self-renewal" blog, please be sure to keep this source http://wyong.blog.51cto.com/1115465/1617542
File upload times recv failure:connection reset by Peer exception resolution