Java Common entity class--runtime class

Source: Internet
Author: User

The use of many of the system's functions is equivalent to Runtime.getruntime (), which shows how closely the connection between the system and runtime is, in fact, the system is dependent on the runtime class.

The runtime functions as follows:

    • viewing system memory

    • Terminating a JVM virtual machine

    • Running System programs

    • Using the close hook

The runtime class differs from the system class, and its functions are mostly static, with only one static function GetRuntime (). Each Java application has a runtime instance that enables the application to connect to its running environment, which allows us to obtain a runtime () instance where the application cannot create its own runtime instance and then invoke other functions.

(1) Viewing system memory

Long Freememory ();//Returns the idle memory of the Java Virtual Machine long maxmemory ();//returns the maximum amount of storage that the Java virtual machine is attempting to use long totalmemory ();//returns the total RAM of the Java Virtual machine

The code is as follows:

Package Org.test.envm;public class Runtimeevnt {public static void main (string[] args) {//TODO auto-generated method stub SYSTEM.OUT.PRINTLN ("Total Memory:" +runtime.getruntime (). TotalMemory ()); SYSTEM.OUT.PRINTLN ("Maximum amount of Memory:" +runtime.getruntime (). MaxMemory ()); SYSTEM.OUT.PRINTLN ("Idle Memory:" +runtime.getruntime (). Freememory ());}}

(2) terminating the virtual machine

You can use exit (int status) to start the shutdown sequence for a virtual machine

You can use halt (int status) to force the termination of a virtual machine that is currently running

(3) Operating System program

1. Open Notepad

Runtime.getruntime (). EXEC ("notepad");

2. Open Word

Runtime.getruntime (). EXEC ("cmd/c start Winword");

3. Perform batch processing

Runtime.getruntime (). EXEC ("cmd.exe/c d:/demo/run.bat");














This article is from the "Ah Cool blog source" blog, please make sure to keep this source http://aku28907.blog.51cto.com/5668513/1773944

Java Common entity class--runtime class

Related Article

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.