在java代碼中獲取JVM參數(shù)的方法
更新時間:2017年01月20日 09:28:07 投稿:jingxian
下面小編就為大家?guī)硪黄趈ava代碼中獲取JVM參數(shù)的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
實(shí)例如下:
MemoryMXBean memorymbean = ManagementFactory.getMemoryMXBean(); MemoryUsage usage = memorymbean.getHeapMemoryUsage(); System.out.println("INIT HEAP: " + usage.getInit()); System.out.println("MAX HEAP: " + usage.getMax()); System.out.println("USE HEAP: " + usage.getUsed()); System.out.println("\nFull Information:"); System.out.println("Heap Memory Usage: " + memorymbean.getHeapMemoryUsage()); System.out.println("Non-Heap Memory Usage: " + memorymbean.getNonHeapMemoryUsage()); List<String> inputArguments = ManagementFactory.getRuntimeMXBean().getInputArguments(); System.out.println("===================java options=============== "); System.out.println(inputArguments); System.out.println("=======================通過java來獲取相關(guān)系統(tǒng)狀態(tài)============================ "); int i = (int)Runtime.getRuntime().totalMemory()/1024;//Java 虛擬機(jī)中的內(nèi)存總量,以字節(jié)為單位 System.out.println("總的內(nèi)存量 i is "+i); int j = (int)Runtime.getRuntime().freeMemory()/1024;//Java 虛擬機(jī)中的空閑內(nèi)存量 System.out.println("空閑內(nèi)存量 j is "+j); System.out.println("最大內(nèi)存量 is "+Runtime.getRuntime().maxMemory()/1024); System.out.println("=======================OperatingSystemMXBean============================ "); OperatingSystemMXBean osm = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); // System.out.println(osm.getFreeSwapSpaceSize()/1024); // System.out.println(osm.getFreePhysicalMemorySize()/1024); // System.out.println(osm.getTotalPhysicalMemorySize()/1024); //獲取操作系統(tǒng)相關(guān)信息 System.out.println("osm.getArch() "+osm.getArch()); System.out.println("osm.getAvailableProcessors() "+osm.getAvailableProcessors()); //System.out.println("osm.getCommittedVirtualMemorySize() "+osm.getCommittedVirtualMemorySize()); System.out.println("osm.getName() "+osm.getName()); //System.out.println("osm.getProcessCpuTime() "+osm.getProcessCpuTime()); System.out.println("osm.getVersion() "+osm.getVersion()); //獲取整個虛擬機(jī)內(nèi)存使用情況 System.out.println("=======================MemoryMXBean============================ "); MemoryMXBean mm=(MemoryMXBean)ManagementFactory.getMemoryMXBean(); System.out.println("getHeapMemoryUsage "+mm.getHeapMemoryUsage()); System.out.println("getNonHeapMemoryUsage "+mm.getNonHeapMemoryUsage()); //獲取各個線程的各種狀態(tài),CPU 占用情況,以及整個系統(tǒng)中的線程狀況 System.out.println("=======================ThreadMXBean============================ "); ThreadMXBean tm=(ThreadMXBean)ManagementFactory.getThreadMXBean(); System.out.println("getThreadCount "+tm.getThreadCount()); System.out.println("getPeakThreadCount "+tm.getPeakThreadCount()); System.out.println("getCurrentThreadCpuTime "+tm.getCurrentThreadCpuTime()); System.out.println("getDaemonThreadCount "+tm.getDaemonThreadCount()); System.out.println("getCurrentThreadUserTime "+tm.getCurrentThreadUserTime()); //當(dāng)前編譯器情況 System.out.println("=======================CompilationMXBean============================ "); CompilationMXBean gm=(CompilationMXBean)ManagementFactory.getCompilationMXBean(); System.out.println("getName "+gm.getName()); System.out.println("getTotalCompilationTime "+gm.getTotalCompilationTime()); //獲取多個內(nèi)存池的使用情況 System.out.println("=======================MemoryPoolMXBean============================ "); List<MemoryPoolMXBean> mpmList=ManagementFactory.getMemoryPoolMXBeans(); for(MemoryPoolMXBean mpm:mpmList){ System.out.println("getUsage "+mpm.getUsage()); System.out.println("getMemoryManagerNames "+mpm.getMemoryManagerNames().toString()); } //獲取GC的次數(shù)以及花費(fèi)時間之類的信息 System.out.println("=======================MemoryPoolMXBean============================ "); List<GarbageCollectorMXBean> gcmList=ManagementFactory.getGarbageCollectorMXBeans(); for(GarbageCollectorMXBean gcm:gcmList){ System.out.println("getName "+gcm.getName()); System.out.println("getMemoryPoolNames "+gcm.getMemoryPoolNames()); } //獲取運(yùn)行時信息 System.out.println("=======================RuntimeMXBean============================ "); RuntimeMXBean rmb=(RuntimeMXBean)ManagementFactory.getRuntimeMXBean(); System.out.println("getClassPath "+rmb.getClassPath()); System.out.println("getLibraryPath "+rmb.getLibraryPath()); System.out.println("getVmVersion "+rmb.getVmVersion());
以上這篇在java代碼中獲取JVM參數(shù)的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
springboot集成spring cache緩存示例代碼
本篇文章主要介紹了springboot集成spring cache示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-05-05springBoot接入阿里云oss的實(shí)現(xiàn)步驟
這篇文章主要介紹了springBoot接入阿里云oss的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01idea新建聚合項(xiàng)目并附上標(biāo)簽的詳細(xì)過程
這篇文章主要介紹了idea新建聚合項(xiàng)目并附上標(biāo)簽的詳細(xì)過程,本文通過實(shí)例圖文相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-08-08java.lang.IllegalArgumentException:Invalid character&nb
本文介紹了java.lang.IllegalArgumentException: Invalid character found異常的解決,方法包括檢查代碼中的方法名,使用合適的HTTP請求方法常量,使用第三方HTTP庫,檢查請求URL以及使用調(diào)試和日志工具,通過這些方法,我們可以解決異常并確保網(wǎng)絡(luò)應(yīng)用程序的正常運(yùn)行2023-10-10基于SpringBoot實(shí)現(xiàn)自定義插件的流程詳解
在SpringBoot中,插件是一種擴(kuò)展機(jī)制,它可以幫助我們在應(yīng)用程序中快速地添加一些額外的功能,在本文中,我們將介紹如何使用 SpringBoot實(shí)現(xiàn)自定義插件,需要的朋友可以參考下2023-06-06