我需要在Java中检查服务器的CPU和内存使用情况,有人知道怎么做吗?
如果你正在专门寻找JVM中的内存:
Runtime runtime = Runtime.getRuntime(); NumberFormat format = NumberFormat.getInstance(); StringBuilder sb = new StringBuilder(); long maxMemory = runtime.maxMemory(); long allocatedMemory = runtime.totalMemory(); long freeMemory = runtime.freeMemory(); sb.append("free memory: " + format.format(freeMemory / 1024) + "<br/>"); sb.append("allocated memory: " + format.format(allocatedMemory / 1024) + "<br/>"); sb.append("max memory: " + format.format(maxMemory / 1024) + "<br/>"); sb.append("total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) + "<br/>");
但是,这些仅应作为估计…