You know how to view JVM memory. Here are a few JVM memory display methods to help you with your learning. Generally, you can use the code to view them, you can also add relevant information in eclipse and view it directly.
JVM memory Display Method
You can view the information in the Code, or add relevant information in eclipse.
1. Use the following code to view JVM memory
1 memory.java 2 3 importjava.lang.Runtime; 4 5 publicclassmemory{ 6 publicstaticvoidmain(Stringargs[]){ 7 System.out.println("usage:"); 8 memorym=newmemory(); 9 longt=m.showUsage(); 10 System.out.println("Total:"+t+"Bytes"); 11 longfr=m.freeMemory(); 12 //System.gc(); 13 System.out.println("Free:"+fr+"Bytes"); 14 longrem=t-fr; 15 System.out.println("OccupiedSpace:"+rem+"Bytes"); 16 } 17 18 publiclongshowUsage(){ 19 longl=Runtime.getRuntime().totalMemory(); 20 return(l); 21 } 22 23 publiclongfreeMemory(){ 24 longf=Runtime.getRuntime().freeMemory(); 25 return(f); 26 } 27 }
2. View JVM memory in eclipse
A. Create a file under the eclipse root directory named "options". Save the file without a suffix. The file content is org. Eclipse. UI/perf/showheapstatus = true.
B. Modify the eclipse. ini file in the eclipse directory and add the following content to the start part of the file:
1-Debug 2 options 3-VM 4 javaw.exe
After you restart eclipse, you can see that the JVM information is added below.
3. How to change the JVM memory size
Java-Xms100m-Xmx250memory