/**Every Java application has a single instance of class Runtime that allows the application to interface withthe environment in which the application is running. The current runtime can be obtained from the getRuntime method.每個(gè)java應(yīng)用有單個(gè)類(lèi)Runtime實(shí)例【讓我想起了單例】,這允許應(yīng)用去和應(yīng)用正在運(yùn)行的環(huán)境交互。目前的runtime對(duì)象能夠從getRuntime()方法中獲得。An application cannot create its own instance of this class.
應(yīng)用程序本身不能創(chuàng)建這個(gè)類(lèi)(Runtime)的實(shí)例@author unascribed@see java.lang.Runtime#getRuntime()@since JDK1.0*/
private static Runtime currentRuntime = new Runtime();
1
getRuntime()方法
/**Returns the runtime object associated with the current Java application.Most of the methods of class Runtime are instance methods and must be invoked with respect to the current runtime object.返回與當(dāng)前Java應(yīng)用關(guān)聯(lián)的runtime對(duì)象。大多數(shù)Runtime類(lèi)的方法是實(shí)例方法,所以必須被調(diào)用與具體的當(dāng)前運(yùn)行時(shí)對(duì)象。@return the Runtime object associated with the current Java application.*/public static Runtime getRuntime() {return currentRuntime;}
1
2
3
4
5
6
7
8
9
availableProcessors()方法
/**Returns the number of processors available to the Java virtual machine.返回Java虛擬機(jī)可用的處理器數(shù)。This value may change during a particular invocation of the virtual machine. Applications that are sensitive to the number of available processors should therefore occasionally poll this property and adjusttheir resource usage appropriately. @return the maximum number of processors available to the virtual machine; never smaller than one@since 1.4*/public native int availableProcessors();
}
1
2
3
4
5
6
7
8
9
10
11
12
exec(String command)方法
/**Executes the specified string command in a separate process.在一個(gè)單獨(dú)的進(jìn)程中執(zhí)行指定的命令。This is a convenience method. An invocation of the form exec(command)behaves in exactly the same way as the invocation #exec(String, String[], File) exec(command, null, null).這是一個(gè)方便的方法。以exec(command)形式調(diào)用與exec(String,Stringp[],file)的表現(xiàn)是相同的。@param command a specified system command.【參數(shù):一個(gè)指定的系統(tǒng)命令】@return A new Process object for managing the subprocess【返回值:一個(gè)新的用于管理子進(jìn)程的的Process對(duì)象】@throws SecurityExceptionIf a security manager exists and its{@link SecurityManager#checkExec checkExec}method doesn't allow creation of the subprocess@throws IOExceptionIf an I/O error occurs@throws NullPointerExceptionIf <code>command</code> is <code>null</code>@throws IllegalArgumentExceptionIf <code>command</code> is empty@see #exec(String[], String[], File)@see ProcessBuilder*/public Process exec(String command) throws IOException {return exec(command, null, null);}