public class Runtime extends Object
getRuntime().System| Modifier and Type | Method and Description |
|---|---|
void |
addShutdownHook(Thread hook)
Registers a VM shutdown hook.
|
int |
availableProcessors()
Returns the number of processor cores available to the VM, at least 1.
|
Process |
exec(String prog)
Executes the specified program in a separate native process.
|
Process |
exec(String[] progArray)
Executes the specified command and its arguments in a separate native
process.
|
Process |
exec(String[] progArray,
String[] envp)
Executes the specified command and its arguments in a separate native
process.
|
Process |
exec(String[] progArray,
String[] envp,
File directory)
Executes the specified command and its arguments in a separate native
process.
|
Process |
exec(String prog,
String[] envp)
Executes the specified program in a separate native process.
|
Process |
exec(String prog,
String[] envp,
File directory)
Executes the specified program in a separate native process.
|
void |
exit(int code)
Causes the VM to stop running and the program to exit.
|
long |
freeMemory()
Returns the number of bytes currently available on the heap without expanding the heap.
|
void |
gc()
Indicates to the VM that it would be a good time to run the
garbage collector.
|
InputStream |
getLocalizedInputStream(InputStream stream)
Deprecated.
Use
InputStreamReader instead. |
OutputStream |
getLocalizedOutputStream(OutputStream stream)
Deprecated.
Use
OutputStreamWriter instead. |
static Runtime |
getRuntime()
Returns the single
Runtime instance for the current application. |
void |
halt(int code)
Causes the VM to stop running, and the program to exit with the given return code.
|
void |
load(String absolutePath)
Loads the shared library found at the given absolute path.
|
void |
load(String absolutePath,
ClassLoader loader)
Loads the given shared library using the given ClassLoader.
|
void |
loadLibrary(String nickname)
Loads a shared library.
|
long |
maxMemory()
Returns the maximum number of bytes the heap can expand to.
|
boolean |
removeShutdownHook(Thread hook)
Unregisters a previously registered VM shutdown hook.
|
void |
runFinalization()
Provides a hint to the runtime that it would be useful to attempt
to perform any outstanding object finalization.
|
static void |
runFinalizersOnExit(boolean run)
Deprecated.
This method is unsafe.
|
long |
totalMemory()
Returns the number of bytes taken by the heap at its current size.
|
void |
traceInstructions(boolean enable)
Switches the output of debug information for instructions on or off.
|
void |
traceMethodCalls(boolean enable)
Switches the output of debug information for methods on or off.
|
public Process exec(String[] progArray) throws IOException
exec(progArray, null, null).progArray - the array containing the program to execute as well as any
arguments to the program.Process object that represents the native
process.IOException - if the requested program can not be executed.public Process exec(String[] progArray, String[] envp) throws IOException
envp.
Calling this method is equivalent to calling
exec(progArray, envp, null).progArray - the array containing the program to execute as well as any
arguments to the program.envp - the array containing the environment to start the new process
in.Process object that represents the native
process.IOException - if the requested program can not be executed.public Process exec(String[] progArray, String[] envp, File directory) throws IOException
envp
and the working directory specified by directory.progArray - the array containing the program to execute as well as any
arguments to the program.envp - the array containing the environment to start the new process
in.directory - the directory in which to execute the program. If null,
execute if in the same directory as the parent process.Process object that represents the native
process.IOException - if the requested program can not be executed.public Process exec(String prog) throws IOException
exec(prog, null, null).prog - the name of the program to execute.Process object that represents the native
process.IOException - if the requested program can not be executed.public Process exec(String prog, String[] envp) throws IOException
envp. Calling this
method is equivalent to calling exec(prog, envp, null).prog - the name of the program to execute.envp - the array containing the environment to start the new process
in.Process object that represents the native
process.IOException - if the requested program can not be executed.public Process exec(String prog, String[] envp, File directory) throws IOException
envp and the working
directory specified by directory.prog - the name of the program to execute.envp - the array containing the environment to start the new process
in.directory - the directory in which to execute the program. If null,
execute if in the same directory as the parent process.Process object that represents the native
process.IOException - if the requested program can not be executed.public void exit(int code)
runFinalizersOnExit(boolean) has been previously invoked with a
true argument, then all objects will be properly
garbage-collected and finalized first.
Use 0 to signal success to the calling process and 1 to signal failure.
This method is unlikely to be useful to an Android application.public void gc()
public static Runtime getRuntime()
Runtime instance for the current application.public void load(String absolutePath)
/path/to/library/libMyLibrary.so.
Most callers should use loadLibrary(String) instead, and
let the system find the correct file to load.UnsatisfiedLinkError - if the library can not be loaded,
either because it's not found or because there is something wrong with it.public void load(String absolutePath, ClassLoader loader)
MOE: We have made this public, because we have to access this from
org.moe.MOE.
public void loadLibrary(String nickname)
Given the name "MyLibrary", that string will be passed to
System.mapLibraryName(java.lang.String). That means it would be a mistake
for the caller to include the usual "lib" prefix and ".so"
suffix.
That file will then be searched for on the application's native library search path. This consists of the application's own native library directory followed by the system's native library directories.
UnsatisfiedLinkError - if the library can not be loaded,
either because it's not found or because there is something wrong with it.public void runFinalization()
@Deprecated public static void runFinalizersOnExit(boolean run)
run - true to enable finalization on exit, false to
disable it.public void traceInstructions(boolean enable)
public void traceMethodCalls(boolean enable)
@Deprecated public InputStream getLocalizedInputStream(InputStream stream)
InputStreamReader instead.stream - the input stream to localize.@Deprecated public OutputStream getLocalizedOutputStream(OutputStream stream)
OutputStreamWriter instead.stream - the output stream to localize.public void addShutdownHook(Thread hook)
Thread that is ready to run, but has not yet been started. All
registered shutdown hooks will be executed when the VM
terminates normally (typically when the exit(int) method is called).
Note that on Android, the application lifecycle does not include VM termination,
so calling this method will not ensure that your code is run. Instead, you should
use the most appropriate lifecycle notification (Activity.onPause, say).
Shutdown hooks are run concurrently and in an unspecified order. Hooks
failing due to an unhandled exception are not a problem, but the stack
trace might be printed to the console. Once initiated, the whole shutdown
process can only be terminated by calling halt().
If runFinalizersOnExit(boolean) has been called with a true argument, garbage collection and finalization will take place after
all hooks are either finished or have failed. Then the VM
terminates.
It is recommended that shutdown hooks do not do any time-consuming activities, in order to not hold up the shutdown process longer than necessary.
hook - the shutdown hook to register.IllegalArgumentException - if the hook has already been started or if it has already
been registered.IllegalStateException - if the VM is already shutting down.public boolean removeShutdownHook(Thread hook)
hook - the shutdown hook to remove.true if the hook has been removed successfully; false otherwise.IllegalStateException - if the VM is already shutting down.public void halt(int code)
public int availableProcessors()
public long freeMemory()
totalMemory() for the heap's current size. When these bytes are exhausted, the heap
may expand. See maxMemory() for that limit.public long totalMemory()
maxMemory() for the maximum heap size, and freeMemory() for an idea of how much
the heap could currently contract.public long maxMemory()
totalMemory() for the
current number of bytes taken by the heap, and freeMemory() for the current number of
those bytes actually used by live objects.