File upload times recv failure:connection reset by Peer exception resolution

Source: Internet
Author: User
Tags connection reset

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.