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