Getting Started with Java--runtime class Know the runtime class
The runtime class represents the runtime's action class, a class that encapsulates the JVM process, each of which corresponds to an instance of the runtime class that is instantiated by the JVM runtime. The methods for obtaining instances of the runtime class are:
Runtime Run=runtime.getruntime ();
You can get some information about the system through the runtime instance.
Package Sep26;public class RuntimeDemo01 {public static void main (string[] args) {Runtime run=runtime.getruntime (); System.out.println ("JVM max Memory:" +run.maxmemory ());//Instantiate Runtime class System.out.println ("JVM Free Memory:" +run.freememory ());// Maximum memory string str= "Guo Congcong" + "\ n" + "is a good man!" "; for (int i=1;i<1000;i++) {str+=i;} Generates multiple garbage System.out.println ("Idle memory after operation of STR:" +run.freememory ()); Run.gc ();//garbage collection frees up space System.out.println (" Free memory after cleaning up garbage: "+run.freememory ());}}
JVM Max Memory: 954728448JVM free Memory: 63120600 free memory after operation of STR: 57416352 free memory after garbage cleanup: 63632776
Getting Started with Java--runtime class