View JVM memory

Source: Internet
Author: User

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

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.