Java.net. socketexception: no buffer space available (maximum connections reached ?) : Jvm_bin

Source: Internet
Author: User

CrawlerProgramAn exception occurred while running,
Java.net. socketexception: no buffer space available (maximum connections reached ?) : Jvm_bin

Httpclient is used in crawlers, And the thread pool is used.

After searching, I found that someone else has a similar problem. The solution is as follows: I changed the program to see if this problem will occur in the future.

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

 

 

A crawler encounters the following exceptions:
Java.net. socketexception no buffer space available (maximum connections reached ?) : Jvm_bind

We know that the operating system has the maximum number of file handles that it can hold. During network connection, each socket request occupies one file handle resource. If it is not released in time, the file handle resource may be exhausted.
Pass CheckCodeIt is found that resources are not released when httpclient is used to send GET requests, and resources are easily exhausted due to multi-threaded programs.
The modified code is as follows:

Java code
  1. Httpclient client =
    New
    Httpclient ();
  2. Getmethod method =
    Null
    ;
  3. Try
    {
  4. Method =
    New
    Getmethod (fig. getuuri (). getescapeduri ());
  5. Statuscode = client.exe cutemethod (method );
  6. //...

  7. }
  8. Finally
    {
  9. If
    (
    Null
    ! = Method)
  10. Method. releaseconnection ();
  11. }

The answer to Sun's technical forum is as follows:
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
Googling for instructions. Or maybe you cocould redesign your program so
That it doesn' t use so much resources.

 

 

 

For more answers to this question, please refer to the following:
Http://forum.java.sun.com/thread.jspa? Threadid = 556382

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.