java.lang
Class Runtime
java.lang.Object
java.lang.Runtime
Method Summary
Modifier and Type | Method and Description |
---|---|
void | addShutdownHook(Thread hook)
Registers a new virtual-machine shutdown hook.
|
int | availableProcessors()
Returns the number of processors available to the Java virtual machine.
|
Process | exec(String command)
Executes the specified string command in a separate process.
|
Process | exec(String[] cmdarray)
Executes the specified command and arguments in a separate process.
|
Process | exec(String[] cmdarray, String[] envp)
Executes the specified command and arguments in a separate process with the specified environment.
|
Process | exec(String[] cmdarray, String[] envp, File dir)
Executes the specified command and arguments in a separate process with the specified environment and working directory.
|
Process | exec(String command, String[] envp)
Executes the specified string command in a separate process with the specified environment.
|
Process | exec(String command, String[] envp, File dir)
Executes the specified string command in a separate process with the specified environment and working directory.
|
void | exit(int status)
Terminates the currently running Java virtual machine by initiating its shutdown sequence.
|
long | freeMemory()
Returns the amount of free memory in the Java Virtual Machine.
|
void | gc()
Runs the garbage collector.
|
InputStream | getLocalizedInputStream(InputStream in)
Deprecated.
As of JDK 1.1, the preferred way to translate a byte stream in the local encoding into a character stream in Unicode is via the
InputStreamReader and BufferedReader classes.
|
OutputStream | getLocalizedOutputStream(OutputStream out)
Deprecated.
As of JDK 1.1, the preferred way to translate a Unicode character stream into a byte stream in the local encoding is via the
OutputStreamWriter , BufferedWriter , and PrintWriter classes.
|
static Runtime | getRuntime()
Returns the runtime object associated with the current Java application.
|
void | halt(int status)
Forcibly terminates the currently running Java virtual machine.
|
void | load(String filename)
Loads the specified filename as a dynamic library.
|
void | loadLibrary(String libname)
Loads the dynamic library with the specified library name.
|
long | maxMemory()
Returns the maximum amount of memory that the Java virtual machine will attempt to use.
|
boolean | removeShutdownHook(Thread hook)
De-registers a previously-registered virtual-machine shutdown hook.
|
void | runFinalization()
Runs the finalization methods of any objects pending finalization.
|
static void | runFinalizersOnExit(boolean value)
Deprecated.
This method is inherently unsafe. It may result in finalizers being called on live objects while other threads are concurrently manipulating those objects, resulting in erratic behavior or deadlock.
|
long | totalMemory()
Returns the total amount of memory in the Java virtual machine.
|
void | traceInstructions(boolean on)
Enables/Disables tracing of instructions.
|
void | traceMethodCalls(boolean on)
Enables/Disables tracing of method calls.
|
public static void main(String[] args) throws IOException, InterruptedException {
/*
* Runtime类,没有构造函数,不可以实例化,但是还提供了非静态的方法。
* 所以应该会提供静态的返回值类型为Runtime的方法获取该对象。
*/
//获取Runtime对象。
Runtime r = Runtime.getRuntime();
//调用exec执行一个程序。
Process p = r.exec("mspaint.exe ");
Thread.sleep(4000);
p.destroy();
}