Package org.miaixz.bus.core.xyz
Class RuntimeKit
java.lang.Object
org.miaixz.bus.core.xyz.RuntimeKit
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddShutdownHook(Runnable hook) 增加一个JVM关闭后的钩子,用于在JVM关闭时执行某些操作static void销毁进程static Process执行命令 命令带参数时参数可作为其中一个参数,也可以将命令和参数组合为一个字符串传入static Process执行命令 命令带参数时参数可作为其中一个参数,也可以将命令和参数组合为一个字符串传入static Process执行命令 命令带参数时参数可作为其中一个参数,也可以将命令和参数组合为一个字符串传入execForLines(String... cmds) 执行系统命令,使用系统默认编码execForLines(Charset charset, String... cmds) 执行系统命令,使用传入的charset编码static StringexecForString(String... cmds) 执行系统命令,使用系统默认编码static StringexecForString(Charset charset, String... cmds) 执行系统命令,使用传入的charset编码static StringgetErrorResult(Process process) 获取命令执行异常结果,使用系统默认编码,获取后销毁进程static StringgetErrorResult(Process process, Charset charset) 获取命令执行异常结果,获取后销毁进程static long获得JVM中剩余的内存数,单位bytestatic long获得JVM中可以从系统中获取的最大的内存数,单位byte,以-Xmx参数为准static intgetPid()获取当前进程ID,首先获取进程名称,读取@前的ID值,如果不存在,则读取进程名的hash值static int获得JVM可用的处理器数量(一般为CPU核心数)static String获取命令执行结果,使用系统默认编码,获取后销毁进程static String获取命令执行结果,获取后销毁进程getResultLines(Process process) 获取命令执行结果,使用系统默认编码,获取后销毁进程getResultLines(Process process, Charset charset) 获取命令执行结果,使用传入的charset编码,获取后销毁进程static long获得JVM已经从系统中获取到的总共的内存数,单位bytestatic long获得JVM最大可用内存,计算方法为: 最大内存-总内存+剩余内存
-
Constructor Details
-
RuntimeKit
public RuntimeKit()
-
-
Method Details
-
execForString
执行系统命令,使用系统默认编码- Parameters:
cmds- 命令列表,每个元素代表一条命令- Returns:
- 执行结果
- Throws:
InternalException- IO异常
-
execForString
执行系统命令,使用传入的charset编码- Parameters:
charset- 编码cmds- 命令列表,每个元素代表一条命令- Returns:
- 执行结果
- Throws:
InternalException- IO异常
-
execForLines
执行系统命令,使用系统默认编码- Parameters:
cmds- 命令列表,每个元素代表一条命令- Returns:
- 执行结果,按行区分
- Throws:
InternalException- IO异常
-
execForLines
执行系统命令,使用传入的charset编码- Parameters:
charset- 编码cmds- 命令列表,每个元素代表一条命令- Returns:
- 执行结果,按行区分
- Throws:
InternalException- IO异常
-
exec
-
exec
-
exec
-
getResultLines
-
getResultLines
-
getResult
-
getResult
-
getErrorResult
-
getErrorResult
-
destroy
-
addShutdownHook
增加一个JVM关闭后的钩子,用于在JVM关闭时执行某些操作- Parameters:
hook- 钩子
-
getProcessorCount
public static int getProcessorCount()获得JVM可用的处理器数量(一般为CPU核心数)这里做一个特殊的处理,在特殊的CPU上面,会有获取不到CPU数量的情况,所以这里做一个保护; 默认给一个7,真实的CPU基本都是偶数,方便区分。 如果不做处理,会出现创建线程池时
ThreadPoolExecutor,抛出异常:IllegalArgumentException- Returns:
- 可用的处理器数量
-
getFreeMemory
public static long getFreeMemory()获得JVM中剩余的内存数,单位byte- Returns:
- JVM中剩余的内存数,单位byte
-
getTotalMemory
public static long getTotalMemory()获得JVM已经从系统中获取到的总共的内存数,单位byte- Returns:
- JVM中剩余的内存数,单位byte
-
getMaxMemory
public static long getMaxMemory()获得JVM中可以从系统中获取的最大的内存数,单位byte,以-Xmx参数为准- Returns:
- JVM中剩余的内存数,单位byte
-
getUsableMemory
public static long getUsableMemory()获得JVM最大可用内存,计算方法为: 最大内存-总内存+剩余内存- Returns:
- 最大可用内存
-
getPid
获取当前进程ID,首先获取进程名称,读取@前的ID值,如果不存在,则读取进程名的hash值- Returns:
- 进程ID
- Throws:
InternalException- 进程名称为空
-