Java Process is disabled after external commands are executed.

Source: Internet
Author: User

01
String cmd = "";
02
Runtime rt = Runtime. getRuntime ();
03
Process p = null;
04
Try {
05
P = rt.exe c (cmd );
06
} Catch (Exception e ){
07
 
08
} Finally {
09
If (p! = Null ){
10
Try {
11
P. waitFor ();
12
} Catch (InterruptedException e ){
13
E. printStackTrace ();
14
}
15
P. destroy ();
16
}
17
}
In the past, we also used Process to execute External commands, such as backing up mysql. Process has never been closed. This write monitoring system obtains information such as memory and cpu in linux and regularly sends jms to the monitoring server. Because process is not disabled, the file descriptor is used up after running for a period of time, and thus the system cannot be logged on. Then we can see that this is also to be closed .. The Code is as above.
Author: Desperate skin

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.