Team LiB
Previous Section Next Section


Java 1.0

This class encapsulates a number of platform-dependent system functions. The static method getruntime( ) returns the Runtime object for the current platform; this object can perform system functions in a platform-independent way.

exit( ) causes the Java interpreter to exit and return a specified return code. This method is usually invoked through System.exit( ). In Java 1.3, addShutdownHook( ) registers an unstarted Thread object that is run when the virtual machine shuts down, either through a call to exit( ) or through a user interrupt (a CTRL-C, for example). The purpose of a shutdown hook is to perform necessary cleanup, such as shutting down network connections, deleting temporary files, and so on. Any number of hooks can be registered with addShutdownHook( ). Before the interpreter exits, it starts all registered shutdown-hook threads and lets them run concurrently. Any hooks you write should perform their cleanup operation and exit promptly so they do not delay the shutdown process. To remove a shutdown hook before it is run, call removeShutdownHook( ). To force an immediate exit that does not invoke the shutdown hooks, call halt( ).

exec( ) starts a new process running externally to the interpreter. Note that any processes run outside of Java may be system-dependent.

freeMemory( ) returns the approximate amount of free memory. totalMemory( ) returns the total amount of memory available to the Java interpreter. gc( ) forces the garbage collector to run synchronously, which may free up more memory. Similarly, runFinalization( ) forces the finalize( ) methods of unreferenced objects to be run immediately. This may free up system resources those objects were holding.

load( ) loads a dynamic library with a fully specified pathname. loadLibrary( ) loads a dynamic library with only the library name specified; it looks in platform-dependent locations for the specified library. These libraries generally contain native code definitions for native methods.

traceInstructions( ) and TRaceMethodCalls( ) enable and disable tracing by the interpreter. These methods are used for debugging or profiling an application. It is not specified how the VM emits the trace information, and VMs are not even required to support this feature.

Note that some of the Runtime methods are more commonly called via the static methods of the System class.

public class Runtime {
// No Constructor
// Public Class Methods
     public static Runtime getRuntime( );  
// Public Instance Methods
1.3  public void addShutdownHook(Thread hook);  
1.4  public int availableProcessors( );                               native
     public Process exec(String[ ] cmdarray) throws;  
     public Process exec(String command) throws;  
     public Process exec(String command, String[ ] envp) throws;  
     public Process exec(String[ ] cmdarray, String[ ] envp) throws;  
1.3  public Process exec(String[ ] cmdarray, String[ ] envp, dir) 
1.3  public Process exec(String command, String[ ] envp, dir) throws;  
     public void exit(int status);  
     public long freeMemory( );                                           native
     public void gc( );                                                   native
1.3  public void halt(int status);  
     public void load(String filename);  
     public void loadLibrary(String libname);  
1.4  public long maxMemory( );                                        native
1.3  public boolean removeShutdownHook(Thread hook);  
     public void runFinalization( );  
     public long totalMemory( );                                          native
     public void traceInstructions(boolean on);                         native
     public void traceMethodCalls(boolean on);                          native
// Deprecated Public Methods
#    public getLocalizedInputStream( in);  
#    public getLocalizedOutputStream( out);  
1.1#  public static void runFinalizersOnExit(boolean value);  

    Team LiB
    Previous Section Next Section