欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

在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緩存示例代碼

    本篇文章主要介紹了springboot集成spring cache示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-05-05
  • java中對字符串每個字符統(tǒng)計(jì)的方法

    java中對字符串每個字符統(tǒng)計(jì)的方法

    java中對字符串每個字符統(tǒng)計(jì)的方法,需要的朋友可以參考一下
    2013-03-03
  • 使用@slf4j找不到符號log的問題及解決

    使用@slf4j找不到符號log的問題及解決

    這篇文章主要介紹了使用@slf4j找不到符號log的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • springBoot接入阿里云oss的實(shí)現(xiàn)步驟

    springBoot接入阿里云oss的實(shí)現(xiàn)步驟

    這篇文章主要介紹了springBoot接入阿里云oss的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • SpringSecurity-2.7中跨域問題解析

    SpringSecurity-2.7中跨域問題解析

    這篇文章主要介紹了SpringSecurity-2.7中跨域問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2024-01-01
  • idea新建聚合項(xiàng)目并附上標(biāo)簽的詳細(xì)過程

    idea新建聚合項(xiàng)目并附上標(biāo)簽的詳細(xì)過程

    這篇文章主要介紹了idea新建聚合項(xiàng)目并附上標(biāo)簽的詳細(xì)過程,本文通過實(shí)例圖文相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-08-08
  • java.lang.IllegalArgumentException:Invalid character found異常解決

    java.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
  • 用Java實(shí)現(xiàn)24點(diǎn)游戲

    用Java實(shí)現(xiàn)24點(diǎn)游戲

    喜歡玩游戲的有福啦,文中有非常詳細(xì)的開發(fā)框架,按著框架來實(shí)現(xiàn)就好啦.而且24點(diǎn)游戲是經(jīng)典的紙牌益智游戲.,需要的朋友可以參考下
    2021-05-05
  • 基于SpringBoot實(shí)現(xiàn)自定義插件的流程詳解

    基于SpringBoot實(shí)現(xiàn)自定義插件的流程詳解

    在SpringBoot中,插件是一種擴(kuò)展機(jī)制,它可以幫助我們在應(yīng)用程序中快速地添加一些額外的功能,在本文中,我們將介紹如何使用 SpringBoot實(shí)現(xiàn)自定義插件,需要的朋友可以參考下
    2023-06-06
  • 詳解SpringBoot和SpringBatch 使用

    詳解SpringBoot和SpringBatch 使用

    Spring Batch 是一個輕量級的、完善的批處理框架,旨在幫助企業(yè)建立健壯、高效的批處理應(yīng)用。這篇文章主要介紹了詳解SpringBoot和SpringBatch 使用,需要的朋友可以參考下
    2018-07-07

最新評論