gpt4 book ai didi

java - 如何在运行时检查服务器的 "JVM/CPU/Memory"?

转载 作者:太空宇宙 更新时间:2023-11-04 08:20:35 26 4
gpt4 key购买 nike

创建作业后,我想将其分配给密度较低的服务器。如何在运行时检查服务器的“JVM/CPU/内存”? (我有4个服务器)(它必须返回一个值给我)

最佳答案

您可以利用系统属性和 Java 管理 API 来完成此操作,无需任何外部依赖项。

这些属性足以确定 VM;

java.vm.specification.version   Java Virtual Machine specification versionjava.vm.specification.vendor    Java Virtual Machine specification vendorjava.vm.specification.name  Java Virtual Machine specification namejava.vm.version         Java Virtual Machine implementation versionjava.vm.vendor          Java Virtual Machine implementation vendorjava.vm.name            Java Virtual Machine implementation namejava.specification.version  Java Runtime Environment specification versionjava.specification.vendor   Java Runtime Environment specification vendorjava.specification.name     Java Runtime Environment specification name

And you can use the following management beans to determine CPU and memory:

ManagementFactory.getMemoryMXBean();
ManagementFactory.getOperatingSystemMXBean();

关于java - 如何在运行时检查服务器的 "JVM/CPU/Memory"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9604758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com