Runtime class and its common methods

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.