Runtime class

Runtime class is the interface to the environment.

Get the instance of a runtime

static Runtime getRuntime()
Returns the runtime object associated with the current Java application.
boolean removeShutdownHook(Thread hook)
De-registers a previously-registered virtual-machine shutdown hook.
int availableProcessors()
Returns the number of processors available to the Java virtual machine.
long freeMemory()
Returns the amount of free memory in the Java Virtual Machine.
long maxMemory()
Returns the maximum amount of memory that the Java virtual machine will attempt to use.
long totalMemory()
Returns the total amount of memory in the Java virtual machine.
Process exec(String command)
Executes the specified string command in a separate process.
Process exec(String command, String[] envp)
Executes the specified string command in a separate process with the specified environment.
Process exec(String command, String[] envp, File dir)
Executes the specified string command in a separate process with the specified environment and working directory.
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[] cmdarray, String[] envp, File dir)
Executes the specified command and arguments in a separate process with the specified environment and working directory.
void addShutdownHook(Thread hook)
Registers a new virtual-machine shutdown hook.
void exit(int status)
Terminates the currently running Java virtual machine by initiating its shutdown sequence.
void gc()
Runs the garbage collector.
void halt(int status)
Terminates the currently running Java virtual machine.
void load(String filename)
Loads the filename as a dynamic library.
void loadLibrary(String libname)
Loads the library with the specified library name.
void runFinalization()
Runs the finalization methods of any objects pending finalization.
void traceInstructions(boolean on)
Enables/Disables tracing of instructions.
void traceMethodCalls(boolean on)
Enables/Disables tracing of method calls.

Revised from Open JDK source code

Home 
  Java Book 
    Essential Classes  

Runtime:
  1. Runtime class
  2. Get the instance of a runtime
  3. Get the memory in your Java virtual machine
  4. Shut down hook
  5. Get the available processor
  6. Exit and halt Java virtual machine
  7. Run garbage collector and finalization methods
  8. Execuate a system command