img
Runtime
The Runtime class encapsulates the run-time environment. You cannot instantiate a Runtime
object. However, you can get a reference to the current Runtime object by calling the static
method Runtime.getRuntime( ). Once you obtain a reference to the current Runtime object,
you can call several methods that control the state and behavior of the Java Virtual Machine.
Applets and other untrusted code typically cannot call any of the Runtime methods without
raising a SecurityException. Commonly used methods defined by Runtime are shown in
Table 16-11.
Method
Description
void addShutdownHook(Thread thrd)
Registers thrd as a thread to be run when the Java
Vir tual Machine terminates.
Process exec(String progName)
Executes the program specified by progName as a
throws IOException
separate process. An object of type Process is
returned that describes the new process.
Process exec(String progName,
Executes the program specified by progName as a
String environment[ ])
separate process with the environment specified by
throws IOException
environment. An object of type Process is returned
that describes the new process.
Process exec(String comLineArray[ ])
Executes the command line specified by the strings in
comLineArray as a separate process. An object of type
throws IOException
Process is returned that describes the new process.
Process exec(String comLineArray[ ],
Executes the command line specified by the strings
String environment[ ])
in comLineArray as a separate process with the
environment specified by environment. An object of type
throws IOException
Process is returned that describes the new process.
void exit(int exitCode)
Halts execution and returns the value of exitCode to
the parent process. By convention, 0 indicates normal
termination. All other values indicate some form of error.
long freeMemor y( )
Returns the approximate number of bytes of free
memor y available to the Java run-time system.
void gc( )
Initiates garbage collection.
static Runtime getRuntime( )
Returns the current Runtime object.
void halt(int code)
Immediately terminates the Java Vir tual Machine. No
termination threads or finalizers are run. The value of
code is returned to the invoking process.
void load(String librar yFileName)
Loads the dynamic librar y whose file is specified by
librar yFileName, which must specify its complete path.
void loadLibrar y(String librar yName)
Loads the dynamic librar y whose name is associated
with librar yName.
TABLE 16-11
A Sampling of Methods Defined by Runtime
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home