Copy from http://www.seotcs.com/blog/796.html
Since the Seotcs system November 24 updated the SEO scoring algorithm, has been bothering me a problem arises, Java Data Job task, in the execution process will often report the following error:
"2011-12-03 18:00:32 defaulthttpclient [INFO] I/O exception (java.net.SocketException) caught when processing Request:co Nnection Reset by Peer:socket write error
2011-12-03 18:00:32 defaulthttpclient [INFO] retrying request "...
For this, I searched the Chinese and english some websites, searched everywhere can find every corner, found that the principle of this situation, the Java exception on the client and the server can occur, the cause of this exception is two:
1, if one end of the socket is closed (or active shutdown, or due to an abnormal exit caused by the shutdown), the other end still sends data, the first packet sent to throw the exception (Connect reset by peer).
2, one end exits, but the connection is not closed when exiting, and the other end throws the exception if the data is read from the connection (Connection reset). The simple thing is that the read and write operations are caused by the disconnection of the connection.
So I simply think that by setting some socket timeout time, you can solve:
But the situation is still the same after setup.
This problem for several days, every day in the thinking and contrast test, in order to find the cause of the code, I can not help thinking, the same number of key words, why before the batch query ranking data without error, and the recent frequent error, this is why? is the requested interface site shielded from our server IP? This reason is not very sufficient, it is certain that there is no reasonable release of the connection connection in the program caused!
Under the guidance of this idea, through a few days of continuous struggle and practice, today finally found the essence of the problem, that is the method of the timer caused! This is the case, these days, I manually triggered some batch tasks, found that in the filter rank value of 100, Java java.net.SocketException:Connection reset this error will always throw, and the brush screen is particularly powerful, After carefully comparing this code of the timer
After, finally suddenly wake up, right! This is the problem here, I will analyze it myself:
A function value, which returns the value, is a critical value, but in my method of the timer, I judge the value returned if it is a critical value, it will force it to continue to execute the method within 10 seconds, and this method is to get a page of source code of a specific data, Each time this method executes, it consumes dozens of milliseconds, which is the equivalent of a socket connection at this time, but since it always returns the critical value, the method will not stop to establish a socket connection for 10 seconds to get the data. If the execution time of this method is approximately 80ms (tested, each such method executes 80 milliseconds or so), in 10 seconds time, will establish 10*1000/80 = 125 socket connection, That is, 12.5 sockets per second, and as a result of this is a filtering program, a number of critical values will continue to appear together, so in a few seconds, the same site page of the number of socket connections will soar high, to hundreds of or even thousands, resulting in waiting for processing the number of request connections is too high:
Why would use this timer method to let a method more than a few times, the reason is to get a stable value of data, but now think, bring the negative impact of how big, the effect is not to be underestimated, but after a few days of comprehensive analysis and testing, finally found the culprit, After the problem solved, the heart, suddenly suddenly, can rest assured sleep ...
A recent tangle of fatal Java error java.net.SocketException:Connection Reset has finally been resolved