java.net.SocketException: No buffer space available (maximum connections reached?): JVM_Bin

來源:互聯網
上載者:User

爬蟲程式運行中出現異常,
java.net.SocketException: No buffer space available (maximum connections reached?): JVM_Bin

爬蟲中使用httpclient,而且是使用了線程池。

搜了下發現,別人也有類似問題,解決辦法如下,照著改了下程式,看看以後運行中是否還會出現這個問題。

 from http://9iopen.group.javaeye.com/group/blog/144545

 

 

在一個爬蟲程式中遇到了以下異常:
java.net.SocketException No buffer space available (maximum connections reached?): JVM_Bind

我們知道,作業系統有它允許持有的最大檔案控制代碼數,而在網路連接的過程中,每個socket請求都要佔用一個檔案控制代碼資源,如果沒有及時釋放,則可能會耗盡檔案控制代碼資源.
通過檢查代碼,發現在使用HttpClient發送Get請求時沒有釋放資源,並且由於是多線程程式,很容易耗盡資源
改寫後的代碼如下: java 代碼 HttpClient client =  new  HttpClient();    GetMethod method =  null ;    try  {    method =  new  GetMethod(crawlerURL.getUURI().getEscapedURI());    statusCode = client.executeMethod(method);    //...    }    finally  {    if  ( null  != method)    method.releaseConnection();    }  

在sun的技術論壇中有一個解答是這樣的:
Chances are you are forgetting to close a socket, a database connection, or some other connection that uses sockets internally. See example program below.
The alternative is that your program (or the sum of all programs running on your computer) really needs a lot of connections. In this case you'll need to find out how to increase the amount of socket buffer space that your operating system allocates. I'd start by googling for instructions. Or maybe you could redesign your program so that it doesn't use so much resources.

 

 

 

更多此問題的解答請看這裡:
http://forum.java.sun.com/thread.jspa?threadID=556382

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.