Java代碼中擷取JVM參數

來源:互聯網
上載者:User

標籤:java代碼   arguments   nbsp   nts   tar   eem   jvm參數   str   div   

 

參考:http://cn-done.iteye.com/blog/2041971

package com.wjz.demo;import java.lang.management.ManagementFactory;import java.lang.management.MemoryMXBean;import java.util.List;public class JVMArgs {    public static void main(String[] args) {        MemoryMXBean memorymbean = ManagementFactory.getMemoryMXBean();        System.out.println("堆記憶體資訊: " + memorymbean.getHeapMemoryUsage());           System.out.println("方法區記憶體資訊: " + memorymbean.getNonHeapMemoryUsage());                 List<String> inputArgs = ManagementFactory.getRuntimeMXBean().getInputArguments();        System.out.println("\n#####################運行時設定的JVM參數#######################");        System.out.println(inputArgs);                System.out.println("\n#####################運行時記憶體情況#######################");        long totle = Runtime.getRuntime().totalMemory();        System.out.println("總的記憶體量 [" + totle + "]");        long free = Runtime.getRuntime().freeMemory();        System.out.println("閒置記憶體量 [" + free + "]");        long max = Runtime.getRuntime().maxMemory();        System.out.println("最大的記憶體量 [" + max + "]");    }}

輸出結果

堆記憶體資訊: init = 20971520(20480K) used = 857216(837K) committed = 20119552(19648K) max = 20119552(19648K)方法區記憶體資訊: init = 24313856(23744K) used = 3082720(3010K) committed = 24313856(23744K) max = 136314880(133120K)#####################運行時設定的JVM參數#######################[-Xmx20M, -Dfile.encoding=UTF-8]#####################運行時記憶體情況#######################總的記憶體量 [20119552]閒置記憶體量 [19262336]最大的記憶體量 [20119552]

 

Java代碼中擷取JVM參數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.