Java Platform 1.2

java.lang
Class Runtime

java.lang.Object
  |
  +--java.lang.Runtime

public class Runtime
extends Object

Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.

An application cannot create its own instance of this class.

Since:
JDK1.0
See Also:
getRuntime()

Method Summary
 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 command, String[] envp)
          Executes the specified string command in a separate process with the specified environment.
 void exit(int status)
          Terminates the currently running Java Virtual Machine.
 long freeMemory()
          Returns the amount of free memory in the system.
 void gc()
          Runs the garbage collector.
 InputStream getLocalizedInputStream(InputStream in)
          Deprecated. As of JDK 1.1, the preferred way 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 load(String filename)
          Loads the specified filename as a dynamic library.
 void loadLibrary(String libname)
          Loads the dynamic library with the specified library name.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getRuntime

public static Runtime getRuntime()
Returns the runtime object associated with the current Java application. Most of the methods of class Runtime are instance methods and must be invoked with respect to the current runtime object.
Returns:
the Runtime object associated with the current Java application.

exit

public void exit(int status)
Terminates the currently running Java Virtual Machine. This method never returns normally.

First, if there is a security manager, its checkExit method is called with the status as its argument. This may result in a security exception.

The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

The method System.exit(int) is the conventional and convenient means of invoking this method.

Parameters:
status - exit status. By convention, a nonzero status code indicates abnormal termination.
Throws:
SecurityException - if a security manager exists and its checkExit method doesn't allow exit with the specified status.
See Also:
SecurityException, SecurityManager.checkExit(int)

runFinalizersOnExit

public 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.
Enable or disable finalization on exit; doing so specifies that the finalizers of all objects that have finalizers that have not yet been automatically invoked are to be run before the Java runtime exits. By default, finalization on exit is disabled.

If there is a security manager, its checkExit method is first called with 0 as its argument to ensure the exit is allowed. This could result in a SecurityException.

Throws:
SecurityException - if a security manager exists and its checkExit method doesn't allow the exit.
Since:
JDK1.1
See Also:
exit(int), gc(), SecurityManager.checkExit(int)

exec

public Process exec(String command)
             throws IOException
Executes the specified string command in a separate process.

The command argument is parsed into tokens and then executed as a command in a separate process. The token parsing is done by a StringTokenizer created by the call:

 new StringTokenizer(command)
 
with no further modifications of the character categories. This method has exactly the same effect as exec(command, null).
Parameters:
command - a specified system command.
Returns:
a Process object for managing the subprocess.
Throws:
SecurityException - if a security manager exists and its checkExec method doesn't allow creation of a subprocess.
See Also:
exec(java.lang.String, java.lang.String[]), SecurityManager.checkExec(java.lang.String)

exec

public Process exec(String command,
                    String[] envp)
             throws IOException
Executes the specified 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 in the order that they were produced by the string tokenizer; it then performs the call exec(cmdarray, envp). The token parsing is done by a StringTokenizer created by the call:

 new StringTokenizer(command)
 
with no further modification of the character categories.
Parameters:
command - a specified system command.
envp - array of strings, each element of which has environment variable settings in format name=value.
Returns:
a Process object for managing the subprocess.
Throws:
SecurityException - if a security manager exists and its checkExec method doesn't allow creation of a subprocess.
See Also:
exec(java.lang.String[]), exec(java.lang.String[], java.lang.String[]), SecurityManager.checkExec(java.lang.String)

exec

public Process exec(String[] cmdarray)
             throws IOException
Executes the specified command and arguments in a separate process.

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).

If there is a security manager, its checkExec method is called with the first component of the array cmdarray as its argument. This may result in a security exception.

Parameters:
cmdarray - array containing the command to call and its arguments.
Returns:
a Process object for managing the subprocess.
Throws:
SecurityException - if a security manager exists and its checkExec method doesn't allow creation of a subprocess.
See Also:
exec(java.lang.String[], java.lang.String[]), SecurityManager.checkExec(java.lang.String)

exec

public Process exec(String[] cmdarray,
                    String[] envp)
             throws IOException
Executes the specified command and arguments in a separate process with the specified environment.

If there is a security manager, its checkExec method is called with the first component of the array cmdarray as its argument. This may result in a security exception.

Given an array of strings cmdarray, representing the tokens of a command line, and an array of strings envp, representing "environment" variable settings, 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 of strings, each element of which has environment variable settings in format name=value.
Returns:
a Process object for managing the subprocess.
Throws:
SecurityException - if a security manager exists and its checkExec method doesn't allow creation of a subprocess.
NullPointerException - if cmdarray is null.
IndexOutOfBoundsException - if cmdarray is an empty array (has length 0).
See Also:
Process, SecurityException, SecurityManager.checkExec(java.lang.String)

freeMemory

public long freeMemory()
Returns the amount of free memory in the system. Calling the gc method 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.

totalMemory

public long totalMemory()
Returns the total amount of memory in the Java Virtual Machine. The value returned by this method may vary over time, depending on the host environment.

Note that the amount of memory required to hold an object of any given type may be implementation-dependent.

Returns:
the total amount of memory currently available for current and future objects, measured in bytes.

gc

public void gc()
Runs the garbage collector. 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 discarded objects.

The name gc stands for "garbage collector". The Java Virtual Machine performs this recycling process automatically as needed, in a separate thread, even if the gc method is not invoked explicitly.

The method System.gc() is hte conventional and convenient means of invoking this method.


runFinalization

public void runFinalization()
Runs the finalization methods of any objects pending finalization. Calling this method suggests that the Java Virtual Machine expend effort toward running the finalize methods 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, in a separate thread, if the runFinalization method is not invoked explicitly.

The method System.runFinalization() is the conventional and convenient means of invoking this method.

See Also:
Object.finalize()

traceInstructions

public void traceInstructions(boolean on)
Enables/Disables tracing of instructions. If the boolean argument is true, this method suggests that the Java Virtual Machine emit debugging information for each instruction in the Java Virtual Machine as it is executed. The format of this information, and the file or other output stream to which it is emitted, depends on the host environment. 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 the detailed instruction trace it is performing.

Parameters:
on - true to enable instruction tracing; false to disable this feature.

traceMethodCalls

public void traceMethodCalls(boolean on)
Enables/Disables tracing of method calls. If the boolean argument is true, this method suggests that the Java Virtual Machine emit debugging information for each method in the Java Virtual Machine as it is called. The format of this information, and the file or other output stream to which it is emitted, depends on the host environment. The virtual machine may ignore this request if it does not support this feature.

Calling this method with argument false suggests that the Java Virtual Machine cease emitting per-call debugging information.

Parameters:
on - true to enable instruction tracing; false to disable this feature.

load

public void load(String filename)
Loads the specified filename as a dynamic library. The filename argument must be a complete pathname. From java_g it will automagically insert "_g" before the ".so" (for example Runtime.getRuntime().load("/home/avh/lib/libX11.so");).

First, if there is a security manager, its checkLink method is called with the filename as its argument. This may result in a security exception.

This is similar to the method loadLibrary(String), but it accepts a general file name as an argument rathan than just a library name, allowing any file of native code to be loaded.

The method System.load(String) is the conventional and convenient means of invoking this method.

Parameters:
filename - the file to load.
Throws:
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the file does not exist.
See Also:
getRuntime(), SecurityException, SecurityManager.checkLink(java.lang.String)

loadLibrary

public void loadLibrary(String libname)
Loads the dynamic library with the specified library name. A file containing native code is loaded from the local file system from a place where library files are conventionally obtained. The details of this process are implementation-dependent. The mapping from a library name to a specific filename is done in a system-specific manner.

First, if there is a security manager, its checkLink method is called with the libname as its argument. This may result in a security exception.

The method System.loadLibrary(String) is the conventional and convenient means of invoking this method. If native methods are to be used in the implementation of a class, a standard strategy is to put the native code in a library file (call it LibFile) and then to put a static initializer:

 static { System.loadLibrary("LibFile"); }
 
within the class declaration. When the class is loaded and initialized, the necessary native code implementation for the native methods will then be loaded as well.

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:
SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
UnsatisfiedLinkError - if the library does not exist.
See Also:
SecurityException, SecurityManager.checkLink(java.lang.String)

getLocalizedInputStream

public InputStream getLocalizedInputStream(InputStream in)
Deprecated. As of JDK 1.1, the preferred way translate a byte stream in the local encoding into a character stream in Unicode is via the InputStreamReader and BufferedReader classes.
Creates a localized version of an input stream. This method takes an InputStream 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.
See Also:
InputStream, BufferedReader.BufferedReader(java.io.Reader), InputStreamReader.InputStreamReader(java.io.InputStream)

getLocalizedOutputStream

public 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.
Creates a localized version of an output stream. This method takes an OutputStream 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.
See Also:
OutputStream, BufferedWriter.BufferedWriter(java.io.Writer), OutputStreamWriter.OutputStreamWriter(java.io.OutputStream), PrintWriter.PrintWriter(java.io.OutputStream)

Java Platform 1.2

Submit a bug or feature Version 1.2 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.