org.apache.catalina.connector.ClientAbortException: java.io.IOException: 您的主機中的軟件中止了一個已建立的連接。


日志文件中有“java.io.IOException: 您的主機中的軟件中止了一個已建立的連接。”錯誤

org.apache.catalina.connector.ClientAbortException: java.io.IOException: 您的主機中的軟件中止了一個已建立的連接。
    at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:396)
    at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:426)
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:345)
    at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:320)
    at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:110)
    at com.fasterxml.jackson.core.json.UTF8JsonGenerator.flush(UTF8JsonGenerator.java:1022)
    at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:2376)
    at ······

 

原因分析:

在tomcat中出現這個錯誤是由於客戶端在發送請求后,還沒等服務器響應就斷開了連接,有可能是因為網絡原因,突然網斷了,但是如果錯誤頻繁出現的話,可能就是服務端的問題了。

tomcat中配置了一個連接超時時間connectionTimeout,如果在這個時間之后客戶端還未得到服務器端的響應的話,就會主動斷開連接,這樣就會出現上述異常了,tomcat中默認的連接超時時間是20秒,我們一般最好設置為60秒,從而避免后台程序處理時間長導致連接斷開。
解決方法:

可以通過設置tomcat下conf文件夾的server.xml文件,對請求連接數和請求超時時間進行設置。

<Connector port="8080" protocol="HTTP/1.1"   
              connectionTimeout="20000"   
              redirectPort="8443" acceptCount="500" maxThreads="400" />  

connectionTimeout以毫秒為單位,默認設置為20秒。通過修改該參數,可以修改tomcat的請求超時時間;


關於修改最大並發請求連接數,需要修改maxThreads和acceptCount兩個參數,

其中,maxThreads的介紹如下:

The maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200. If an executor is associated with this connector, this attribute is ignored as the connector will execute tasks using the executor rather than an internal thread pool.

而acceptCount的介紹為:

The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.

所以兩者的默認值分別是200和100,要調整Tomcat的默認最大連接數,可以增加這兩個屬性的值,並且使acceptCount大於等於maxThreads

 


原文鏈接:https://blog.csdn.net/wujiandao000/article/details/79068100

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM