JavaAPI
JavaAPI
AnnotationUtils.findAnnotation
作用- AnnotationUtils.findAnnotation() 是 Spring 框架提供的注解查找工具方法,主要功能是从类/方法/字段上获取指定类型的注解
示例- 左边给具体要查找哪个类,右边给要查找的哪个注解
- AnnotationUtils.findAnnotation(logic.getClass(), LogicStrategy.class);
- 还可以传方法
public static <A extends Annotation> A findAnnotation(Method method, @Nullable Class<A> annotationType)
- 对应的还有
- AnnotationUtils.find
通过CLass获取类中属性
利用反射获得 Unsafe 类中已经实例化完成的单例对象 theUnsafe 。
private static Unsafe reflectGetUnsafe() {
try {
Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
return (Unsafe) field.get(null);
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
获得处理器数量
Runtime.getRuntime().availableProcessors()
更新: 2025-10-12 17:17:15
原文: https://www.yuque.com/duifangzhengzaishuru-rqbua/axyc58/gwlpuoq0qdaaemrk