public class TEnv extends Object
Modifier and Type | Field and Description |
---|---|
static Instrumentation |
instrumentation |
static boolean |
IS_SHUTDOWN |
static Float |
JDK_VERSION |
static Thread |
MAIN_THREAD |
static String |
OS_NAME |
static Vector<Runnable> |
SHUT_DOWN_HOOKS |
Constructor and Description |
---|
TEnv() |
Modifier and Type | Method and Description |
---|---|
static void |
addShutDownHook(Runnable hook)
增加进程结束的 hook 操作
|
static Instrumentation |
agentAttach(String agentJarPath)
附加 Agentjar 到目标地址
|
static boolean |
classInCurrentStack(String clazzName,
String method)
判断指定的 Class 的方法是否在当前的线程栈中
|
static String |
classToResource(Class clazz)
将class 转换成 资源资源文件路径
|
static Process |
createSysProcess(String command,
String[] env,
File workDir)
构造一个系统进程
|
static Process |
createSysProcess(String command,
String[] env,
String workDir)
构造一个系统进程
|
static String |
getClassLocation(Class clazz)
获取 Class 在物理设备上的文件位置
|
static long |
getClassModifyTime(Class clazz)
获取 Class 的修改时间
|
static List<String> |
getClassPath()
获取类 Class Path
因部分 ide 会自动增加全部的 jvm 的 classpath, 所以这里会自动剔除 classpath 中 jvm 的 classPath
|
static long |
getCurrentPID()
获取当前进程 PID
|
static List<Class> |
getDirectorClass(File rootfile,
String pattern,
Class[] filters)
从指定 File 对象寻找 Class
|
static String |
getEnvName()
获取环境的配置名
|
static List<Class> |
getJarClass(File jarFile,
String pattern,
Class[] filters)
从指定jar 文件中寻找 Class
|
static String |
getJavaHome()
返回当前 jvm 的 JAVA_HOME 参数
|
static Thread |
getMainThread()
获取进程的主线程
|
static StackTraceElement[] |
getStackElements()
获取当前栈信息
|
static String |
getStackElementsMessage(StackTraceElement[] stackTraceElements)
获取当前栈信息
|
static String |
getStackMessage()
获取当前栈信息
会自动过滤掉栈里的第一行,即当前类的信息
|
static <T> T |
getSystemProperty(String propertyName,
Class clazz) |
static <T> T |
getSystemProperty(String propertyName,
T defVal) |
static Thread[] |
getThreads()
获取JVM中的所有线程
|
static byte[] |
loadClassBytes(Class clazz)
读取 Class 的字节码
|
static long |
measure(Runnable runnable)
性能测试方法
不需要响应
|
static void |
measure(String msg,
Runnable runnable)
性能测试方法
|
static void |
measure(String msg,
Runnable runnable,
TimeUnit timeUnit)
性能测试方法
|
static List |
measure(String msg,
Supplier supplier)
性能测试方法
|
static List |
measure(String msg,
Supplier supplier,
TimeUnit timeUnit)
性能测试方法
|
static List |
measure(Supplier supplier)
性能测试方法
|
static Class |
resourceToClass(String resourcePath)
将资源文件路径 转换成 Class
|
static List<Class> |
searchClassInEnv(String pattern,
Class[] filters)
从当前进程的ClassPath中寻找 Class
|
static void |
setEnvName(String envName)
设置环境的配置名
|
static boolean |
sleep(int sleepTime)
休眠函数
|
static boolean |
sleep(TimeUnit timeUnit,
int sleepTime)
休眠函数
|
static boolean |
wait(int waitTime,
boolean isCLH,
Supplier<Boolean> supplier)
等待函数
|
static boolean |
wait(int waitTime,
Supplier<Boolean> supplier)
等待函数
|
static boolean |
wait(Supplier<Boolean> supplier)
等待函数
|
static void |
waitThrow(int waitTime,
Supplier<Boolean> supplier)
等待函数
|
public static Float JDK_VERSION
public static String OS_NAME
public static Thread MAIN_THREAD
public static volatile boolean IS_SHUTDOWN
public static Instrumentation instrumentation
public static void addShutDownHook(Runnable hook)
hook
- 进程结束时的操作对象public static String getEnvName()
public static void setEnvName(String envName)
envName
- 环境的配置名public static long getCurrentPID()
public static Process createSysProcess(String command, String[] env, File workDir) throws IOException
command
- 命令行env
- 环境变量参数workDir
- 工作目录IOException
- IO 异常public static Process createSysProcess(String command, String[] env, String workDir) throws IOException
command
- 命令行env
- 环境变量参数workDir
- 工作目录IOException
- IO 异常public static boolean sleep(int sleepTime)
sleepTime
- 休眠时间public static boolean sleep(TimeUnit timeUnit, int sleepTime)
timeUnit
- 休眠时间单位sleepTime
- 休眠时间public static StackTraceElement[] getStackElements()
public static boolean classInCurrentStack(String clazzName, String method)
clazzName
- 类对象method
- 方法名public static String getStackMessage()
public static String getStackElementsMessage(StackTraceElement[] stackTraceElements)
stackTraceElements
- 栈信息对象数组public static Thread[] getThreads()
public static Thread getMainThread()
public static List<Class> searchClassInEnv(String pattern, Class[] filters) throws IOException
pattern
- 确认匹配的正则表达式filters
- 过滤的 class, 满足这些条件的 class 才会被搜索到(注解,接口,继承的类)IOException
- IO 异常public static List<Class> getDirectorClass(File rootfile, String pattern, Class[] filters) throws IOException
rootfile
- 文件目录 File 对象pattern
- 确认匹配的正则表达式filters
- 过滤的 class, 满足这些条件的 class 才会被搜索到(注解,接口,继承的类)IOException
- IO 异常public static List<Class> getJarClass(File jarFile, String pattern, Class[] filters) throws IOException
jarFile
- jar 文件 File 对象pattern
- 确认匹配的正则表达式filters
- 过滤的 class, 满足这些条件的 class 才会被搜索到(注解,接口,继承的类)IOException
- IO 异常public static byte[] loadClassBytes(Class clazz)
clazz
- Class 对象public static String getClassLocation(Class clazz)
clazz
- Class 对象public static long getClassModifyTime(Class clazz)
clazz
- Class 对象public static List<String> getClassPath()
public static String classToResource(Class clazz)
clazz
- Class对象public static Class resourceToClass(String resourcePath) throws ClassNotFoundException
resourcePath
- 资源资源文件路径ClassNotFoundException
- 类未找到异常public static String getJavaHome()
public static Instrumentation agentAttach(String agentJarPath) throws IOException, com.sun.tools.attach.AttachNotSupportedException, com.sun.tools.attach.AgentLoadException, com.sun.tools.attach.AgentInitializationException
agentJarPath
- AgentJar 文件IOException
- IO 异常com.sun.tools.attach.AttachNotSupportedException
- 附加指定进程失败com.sun.tools.attach.AgentLoadException
- Agent 加载异常com.sun.tools.attach.AgentInitializationException
- Agent 初始化异常public static void waitThrow(int waitTime, Supplier<Boolean> supplier) throws TimeoutException
waitTime
- 等待时间supplier
- 满足条件时一直等待, 如果该方法返回 true 一直等待, false 达到预期退出等待TimeoutException
- 超时异常public static boolean wait(int waitTime, Supplier<Boolean> supplier)
waitTime
- 等待时间supplier
- 满足条件时一直等待, 如果该方法返回 true 一直等待, false 达到预期退出等待public static boolean wait(int waitTime, boolean isCLH, Supplier<Boolean> supplier)
waitTime
- 等待时间isCLH
- 是否启用自旋supplier
- 满足条件时一直等待, 如果该方法返回 true 一直等待, false 达到预期退出等待public static boolean wait(Supplier<Boolean> supplier)
supplier
- 满足条件时一直等待, 如果该方法返回 true 一直等待, false 达到预期退出等待public static List measure(Supplier supplier)
supplier
- 执行器public static long measure(Runnable runnable)
runnable
- 执行器public static List measure(String msg, Supplier supplier, TimeUnit timeUnit)
msg
- 输出的消息supplier
- 执行器timeUnit
- 输出的时间单位public static List measure(String msg, Supplier supplier)
msg
- 输出的消息supplier
- 执行器public static void measure(String msg, Runnable runnable)
msg
- 输出的消息runnable
- 执行器public static void measure(String msg, Runnable runnable, TimeUnit timeUnit)
msg
- 输出的消息runnable
- 执行器timeUnit
- 输出的时间单位public static <T> T getSystemProperty(String propertyName, T defVal)
Copyright © 2020 Voovan. All rights reserved.