|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Runtime
public class Runtime
Runtime represents the Virtual Machine.
Method Summary | |
---|---|
void |
addShutdownHook(Thread hook)
Register a new shutdown hook. |
int |
availableProcessors()
Returns the number of available processors currently available to the virtual machine. |
Process |
exec(String cmdline)
Create a new subprocess with the specified command line. |
Process |
exec(String[] cmd)
Create a new subprocess with the specified command line, already tokenized. |
Process |
exec(String[] cmd,
String[] env)
Create a new subprocess with the specified command line, already tokenized, and specified environment. |
Process |
exec(String[] cmd,
String[] env,
File dir)
Create a new subprocess with the specified command line, already tokenized, and the specified environment and working directory. |
Process |
exec(String cmdline,
String[] env)
Create a new subprocess with the specified command line and environment. |
Process |
exec(String cmdline,
String[] env,
File dir)
Create a new subprocess with the specified command line, environment, and working directory. |
void |
exit(int status)
Exit the Java runtime. |
long |
freeMemory()
Find out how much memory is still free for allocating Objects on the heap. |
void |
gc()
Run the garbage collector. |
InputStream |
getLocalizedInputStream(InputStream in)
Deprecated. InputStreamReader is the preferred way to read
local encodings |
OutputStream |
getLocalizedOutputStream(OutputStream out)
Deprecated. OutputStreamWriter is the preferred way to write
local encodings |
static Runtime |
getRuntime()
Get the current Runtime object for this JVM. |
void |
halt(int status)
Forcibly terminate the virtual machine. |
void |
load(String filename)
Load a native library using the system-dependent filename. |
void |
loadLibrary(String libname)
Load a native library using a system-independent "short name" for the library. |
long |
maxMemory()
Returns the maximum amount of memory the virtual machine can attempt to use. |
boolean |
removeShutdownHook(Thread hook)
De-register a shutdown hook. |
void |
runFinalization()
Run finalization on all Objects that are waiting to be finalized. |
static void |
runFinalizersOnExit(boolean finalizeOnExit)
Deprecated. never rely on finalizers to do a clean, thread-safe, mop-up from your code |
long |
totalMemory()
Find out how much memory total is available on the heap for allocating Objects. |
void |
traceInstructions(boolean on)
Tell the VM to trace every bytecode instruction that executes (print out a trace of it). |
void |
traceMethodCalls(boolean on)
Tell the VM to trace every method call that executes (print out a trace of it). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Runtime getRuntime()
public void exit(int status)
checkExit(status)
.
First, all shutdown hooks are run, in unspecified order, and
concurrently. Next, if finalization on exit has been enabled, all pending
finalizers are run. Finally, the system calls halt
.
If this is run a second time after shutdown has already started, there
are two actions. If shutdown hooks are still executing, it blocks
indefinitely. Otherwise, if the status is nonzero it halts immediately;
if it is zero, it blocks indefinitely. This is typically called by
System.exit
.
status
- the status to exit with
SecurityException
- if permission is deniedaddShutdownHook(Thread)
,
runFinalizersOnExit(boolean)
,
runFinalization()
,
halt(int)
public void addShutdownHook(Thread hook)
System.exit
was invoked), or when the user terminates
the virtual machine (such as by typing ^C, or logging off). There is
a security check to add hooks,
RuntimePermission("shutdownHooks")
.
The hook must be an initialized, but unstarted Thread. The threads
are run concurrently, and started in an arbitrary order; and user
threads or daemons may still be running. Once shutdown hooks have
started, they must all complete, or else you must use halt
,
to actually finish the shutdown sequence. Attempts to modify hooks
after shutdown has started result in IllegalStateExceptions.
It is imperative that you code shutdown hooks defensively, as you do not want to deadlock, and have no idea what other hooks will be running concurrently. It is also a good idea to finish quickly, as the virtual machine really wants to shut down!
There are no guarantees that such hooks will run, as there are ways to forcibly kill a process. But in such a drastic case, shutdown hooks would do little for you in the first place.
hook
- an initialized, unstarted Thread
IllegalArgumentException
- if the hook is already registered or run
IllegalStateException
- if the virtual machine is already in
the shutdown sequence
SecurityException
- if permission is deniedremoveShutdownHook(Thread)
,
exit(int)
,
halt(int)
public boolean removeShutdownHook(Thread hook)
RuntimePermission("shutdownHooks")
.
hook
- the hook to remove
IllegalStateException
- if the virtual machine is already in
the shutdown sequence
SecurityException
- if permission is deniedaddShutdownHook(Thread)
,
exit(int)
,
halt(int)
public void halt(int status)
exit
, as it bypasses all shutdown
hooks and initializers. Use caution in calling this! Of course, there is
a security check, checkExit(status)
.
status
- the status to exit with
SecurityException
- if permission is deniedexit(int)
,
addShutdownHook(Thread)
public static void runFinalizersOnExit(boolean finalizeOnExit)
false
. There is a security check, checkExit(0)
.
finalizeOnExit
- whether to finalize all Objects on exit
SecurityException
- if permission is deniedexit(int)
,
gc()
public Process exec(String cmdline) throws IOException
exec(cmdline, null, null)
. A security check is performed,
checkExec
.
cmdline
- the command to call
SecurityException
- if permission is denied
IOException
- if an I/O error occurs
NullPointerException
- if cmdline is null
IndexOutOfBoundsException
- if cmdline is ""public Process exec(String cmdline, String[] env) throws IOException
exec(cmdline, env, null)
. A security
check is performed, checkExec
.
cmdline
- the command to callenv
- the environment to use, in the format name=value
SecurityException
- if permission is denied
IOException
- if an I/O error occurs
NullPointerException
- if cmdline is null, or env has null entries
IndexOutOfBoundsException
- if cmdline is ""public Process exec(String cmdline, String[] env, File dir) throws IOException
exec(cmdArray, env, dir)
. A security check is performed,
checkExec
.
cmdline
- the command to callenv
- the environment to use, in the format name=valuedir
- the working directory to use
SecurityException
- if permission is denied
IOException
- if an I/O error occurs
NullPointerException
- if cmdline is null, or env has null entries
IndexOutOfBoundsException
- if cmdline is ""public Process exec(String[] cmd) throws IOException
exec(cmd, null, null)
. A security check
is performed, checkExec
.
cmd
- the command to call
SecurityException
- if permission is denied
IOException
- if an I/O error occurs
NullPointerException
- if cmd is null, or has null entries
IndexOutOfBoundsException
- if cmd is length 0public Process exec(String[] cmd, String[] env) throws IOException
exec(cmd, env, null)
. A security check is performed,
checkExec
.
cmd
- the command to callenv
- the environment to use, in the format name=value
SecurityException
- if permission is denied
IOException
- if an I/O error occurs
NullPointerException
- if cmd is null, or cmd or env has null
entries
IndexOutOfBoundsException
- if cmd is length 0public Process exec(String[] cmd, String[] env, File dir) throws IOException
checkExec
.
cmd
- the command to callenv
- the environment to use, in the format name=valuedir
- the working directory to use
SecurityException
- if permission is denied
IOException
- if an I/O error occurs
NullPointerException
- if cmd is null, or cmd or env has null
entries
IndexOutOfBoundsException
- if cmd is length 0public int availableProcessors()
public long freeMemory()
public long totalMemory()
public long maxMemory()
Long.MAX_VALUE
if there is no inherent
limit (or if you really do have a 8 exabyte memory!).
public void gc()
public void runFinalization()
gc()
. This calls the
finalize
method of all objects waiting to be collected.
Object.finalize()
public void traceInstructions(boolean on)
on
- whether to turn instruction tracing onpublic void traceMethodCalls(boolean on)
on
- whether to turn method tracing onpublic void load(String filename)
checkLink
.
filename
- the file to load
SecurityException
- if permission is denied
UnsatisfiedLinkError
- if the library is not foundpublic void loadLibrary(String libname)
cl.findLibrary(libpath)
is
used to convert the name. If that result was null, or there was no class
loader, this searches each directory of the system property
java.library.path
for a file named
System.mapLibraryName(libname)
. There may be a security
check, of checkLink
.
libname
- the library to load
SecurityException
- if permission is denied
UnsatisfiedLinkError
- if the library is not foundSystem.mapLibraryName(String)
,
ClassLoader.findLibrary(String)
public InputStream getLocalizedInputStream(InputStream in)
InputStreamReader
is the preferred way to read
local encodings
in
- the stream to localize
public OutputStream getLocalizedOutputStream(OutputStream out)
OutputStreamWriter
is the preferred way to write
local encodings
out
- the stream to localize
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |