Each Java application has a Runtime
class instance that enables the application to connect to the environment in which it is running. The current runtime can be obtained by means of a getRuntime
method.
Common methods:
1, public static Runtime getruntime()
Returns the run-time object associated with the current Java application. Runtime
most methods of a class are instance methods, and they must be called according to the current run-time object.
2. Process
exec(String command)
Executes the specified string command in a separate process.
3. long
freeMemory()
Returns the amount of idle memory in a Java virtual machine.
4. long
maxMemory()
Returns the maximum amount of memory that the Java virtual machine is attempting to use.
5. long
totalMemory()
Returns the total amount of memory in the Java virtual machine.
1 Public classRuntimetest {2 Public Static voidMain (string[] args)throwsIOException, interruptedexception{3Runtime runtime = Runtime.getruntime ();//get run-time object4 //executes the specified string command in a separate process. 5Process Procee = runtime.exec ("C:\\windows\\notepad.exe");6Thread.Sleep (3000);7 Procee.destroy ();8 //memory size, in bytes9SYSTEM.OUT.PRINTLN ("The amount of idle memory in the Java Virtual machine. "+runtime.freememory ());TenSYSTEM.OUT.PRINTLN ("Maximum amount of memory that the Java virtual machine is trying to use:" +runtime.maxmemory ()); OneSystem.out.println ("Returns the total amount of memory in the Java virtual machine:" +runtime.totalmemory ()); A } -}
View Code
Runtime class and its common methods