Improper use of the Runtime class caused by Too many open files

Source: Internet
Author: User

The previous period of time found that the project after a period of time, began to error Java.net.SocketException:Too many open files. Guess where there is a situation where there is no shutdown after opening the stream, that is, there is a leak. Swept the code, it seems that there is no improper location, there is an exception to capture, there is in the finally in the convection closed. After the patient debugging found the problem, the program has used the following methods:

Runtime.getRuntime.exec (CMD).

Discover three streams open here (lsof-p pid can be used on Linux | Wc-l authentication, each call to the method, the number increased by 3). Three streams are inputstream,outputstream and Errorstream respectively. In the program, only two of these streams are closed. Therefore, each call to this method will cause 1 file leaks. After a long run, it exceeds the set file limit.

The most troublesome thing to divulge. So the code still has to be handled with caution, open the forget to close. Also have a good understanding of the Java API used to do it.

Improper use of the Runtime class caused by Too many open files

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.