Packages This Package Prev Next Index
§1.14 Class Runtime
public class java.lang.Runtime
extends java.lang.Object (I-§1.12)
{
// Methods
public Process exec(String command); §1.14.1
public Process exec(String command, String envp[]); §1.14.2
public Process exec(String cmdarray[]); §1.14.3
public Process exec(String cmdarray[], String envp[]); §1.14.4
public void exit(int status); §1.14.5
public long freeMemory(); §1.14.6
public void gc(); §1.14.7
public InputStream getLocalizedInputStream(InputStream in); §1.14.8
public OutputStream getLocalizedOutputStream(OutputStream out); §1.14.9
public static Runtime getRuntime(); §1.14.10
public void load(String filename); §1.14.11
public void loadLibrary(String libname); §1.14.12
public void runFinalization(); §1.14.13
public long totalMemory(); §1.14.14
public void traceInstructions(boolean on); §1.14.15
public void traceMethodCalls(boolean on); §1.14.16
}
Every Java application has a single instance of class Runtime which allows the application
to interface with the environment in which the application is running. The current runtime
can be obtained from the getRuntime method (I-§1.14.10).
An application cannot create its own instance of this class.
exec
public Process exec(String command)
throws IOException
- Executes the string command in a separate process.
- The command argument is parsed into tokens and then executed as a command in a separate process. This method has exactly the same effect as
exec(command, null) (I-§1.14.2).
- Parameters:
command
-
a specified system command
- Returns:
- a Process (I-§1.13) object for managing the subprocess.
- Throws
- SecurityException (I-§1.43)
- If the current thread cannot create a subprocess.
exec
public Process exec(String command, String envp[])
throws IOException
- Executes the string command in a separate process with the specified environment..
- This method breaks the command string into tokens and creates a new array
cmdarray containing the tokens; it then performs the call exec(cmdarray, envp)
(I-§1.14.4).
- Parameters:
command
-
a specified system command
envp
-
array containing environment in format name=value
- Returns:
- a Process (I-§1.13) object for managing the subprocess.
- Throws
- SecurityException (I-§1.43)
- If the current thread cannot create a subprocess.
exec
public Process exec(String cmdarray[])
throws IOException
- Executes the command in a separate process with the specified arguments.
- The command specified by the tokens in cmdarray is executed as a command
in a separate process. This has exactly the same effect as exec(cmdarray, null)
(I-§1.14.4).
- Parameters:
cmdarray
-
array containing the command to call and its arguments
- Returns:
- a Process (I-§1.13) object for managing the subprocess.
- Throws
- SecurityException (I-§1.43)
- If the current thread cannot create a subprocess.
exec
public Process exec(String cmdarray[], String envp[])
throws IOException
- Executes the command in a separate process with the specified arguments
and the specified environment.
- If there is a security manager, its checkExec method (I-§1.15.10) is called
with the first component of the array cmdarray as its argument. This may
result in a security exception (I-§1.43).
- Given an array of strings cmdarray, representing the tokens of a command
line, and an array of strings envp, representing an "environment" that
defines system properties, this method creates a new process in which to
execute the specified command,
- Parameters:
cmdarray
-
array containing the command to call and its arguments
envp
-
array containing environment in format name=value
- Returns:
- a Process (I-§1.13) object for managing the subprocess.
- Throws
- SecurityException (I-§1.43)
- If the current thread cannot create a subprocess.
exit
public void exit(int status)
- Terminates the currently running Java Virtual Machine. This method never
returns normally
- If there is a security manager, its checkExit method (I-§1.15.11) is called
with the status as its argument. This may result in a security exception.
(I-§1.43)
- The argument serves as a status code; by convention, a nonzero status code
indicates abnormal termination.
- Parameters:
status
-
exit status
- Throws
- SecurityException (I-§1.43)
- If the current thread cannot exit with the specified status.
freeMemory
public long freeMemory()
- Determines the amount of free memory in the system. The value returned
by this method is always less than the value returned by the total-Memory
method (I-§1.14.14). Calling the gc method (I-§1.14.7) may result in
increasing the value returned by freeMemory.
- Returns:
- an approximation to the total amount of memory currently available
for future allocated objects, measured in bytes, is returned. .
gc
public void gc()
- Calling this method suggests that the Java Virtual Machine expend effort
toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the
method call, the Java Virtual Machine has made its best effort to recycle
all unused objects.
- The name gc stands for "garbage collector." The Java Virtual Machine performs this recycling process automatically as needed even if the gc method
is not invoked explicitly.
getLocalizedInputStream
public InputStream getLocalizedInputStream(InputStream in)
- Creates a localized version of an input stream. This method takes an InputStream (I-§2.13) and returns an InputStream equivalent to the argument in all
respects except that it is localized: as characters in the local character set
are read from the stream, they are automatically converted from the local
character set to Unicode.
- If the argument is already a localized stream, it may be returned as the
result.
- Returns:
- a localized input stream.
-
getLocalizedOutputStream
public OutputStream getLocalizedOutputStream(OutputStream out)
- Creates a localized version of an output stream. This method takes an OutputStream (I-§2.15) and returns an OutputStream equivalent to the argument in
all respects except that it is localized: as Unicode characters are written to
the stream, they are automatically converted to the local character set.
- If the argument is already a localized stream, it may be returned as the
result.
- Returns:
- a localized output stream.
getRuntime
public static Runtime getRuntime()
- Returns:
- the Runtime object associated with the current Java application.
load
public void load(String filename)
- Loads the given filename as a dynamic library. The filename argument
must be a complete path name.
- If there is a security manager, its checkLink method (I-§1.15.12) is called
with the filename as its argument. This may result in an security exception
(I-§1.43).
- Parameters:
filename
-
the file to load
- Throws
- UnsatisfiedLinkError (I-§1.61)
- If the file does not exist.
- Throws
- SecurityException (I-§1.43)
- If the current thread cannot load the specified dynamic library.
loadLibrary
public void loadLibrary(String libname)
- Loads the dynamic library with the specified library name. The mapping
from a library name to a specific filename is done is a system-specific
manner.
- First, if there is a security manager, its checkLink method (I-§1.15.12) is
called with the filename as its argument. This may result in an security
exception (I-§1.43).
- If this method is called more than once with the same library name, the
second and subsequent calls are ignored.
- Parameters:
libname
-
the name of the library
- Throws
- UnsatisfiedLinkError (I-§1.61)
- If the library does not exist.
- Throws
- SecurityException (I-§1.43)
- If the current thread cannot load the specified dynamic library.
runFinalization
public void runFinalization()
- Calling this method suggests that the Java Virtual Machine expend effort
toward running the finalize methods (I-§1.12.4) of objects that have been
found to be discarded but whose finalize methods have not yet been run.
When control returns from the method call, the Java Virtual Machine has
made a best effort to complete all outstanding finalizations.
- The Java Virtual Machine performs the finalization process automatically
as needed if the runFinalization method is not invoked explicitly.
totalMemory
public long totalMemory()
- Determines the total amount of memory in the Java Virtual Machine.
- Returns:
- the total amount of memory currently available for allocating objects,
measured in bytes.
traceInstructions
public void traceInstructions(boolean on)
- If the boolean argument is true, this method asks the Java Virtual Machine to
print out a detailed trace of each instruction in the Java Virtual Machine as
it is executed. The virtual machine may ignore this request if it does not
support this feature. The destination of the trace output is system-dependent.
- If the boolean argument is false, this method causes the Java Virtual
Machine to stop performing a detailed instruction trace it is performing.
- Parameters:
on
-
true to enable instruction tracing; false to disable this feature
traceMethodCalls
public void traceMethodCalls(boolean on)
- If the boolean argument is true, this method asks the Java Virtual Machine to
print out a detailed trace of each method in the Java Virtual Machine as it
is called. The virtual machine may ignore this request if it does not support
this feature. The destination of the trace output is system-dependent.
- If the boolean argument is false, this method causes the Java Virtual
Machine to stop performing a detailed method trace it is performing.
- Parameters:
on
-
true to enable instruction tracing; false to disable this feature
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com