Get memory and CPU usage

后端 未结 5 1080
失恋的感觉
失恋的感觉 2020-12-09 21:08

I would like to get the total physical memory, the CPU usage, and and the amount of memory being used. I have looked into Runtime.freeMemory(), but that isn\'t

5条回答
  •  情书的邮戳
    2020-12-09 21:26

    Memory and CPU.

    CPU example:

    static final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
          ...
    
        long start = threadBean.getCurrentThreadCpuTime();
         for (int i = 0; i < 10000000; i++) {
            ...
         }
        long finish = threadBean.getCurrentThreadCpuTime();
    

提交回复
热议问题