@InterfaceAudience.Private public class ReflectionUtils extends Object
Modifier and Type | Field and Description |
---|---|
private static long |
previousLogTime |
private static ThreadMXBean |
threadBean |
Constructor and Description |
---|
ReflectionUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> Constructor<T> |
findConstructor(Class<T> type,
Object... paramTypes) |
private static Class<?>[] |
getParameterTypes(Object[] params) |
private static String |
getTaskName(long id,
String name) |
private static <T> T |
instantiate(String className,
Constructor<T> ctor,
Object[] ctorArgs) |
static <T> T |
instantiateWithCustomCtor(String className,
Class<?>[] ctorArgTypes,
Object[] ctorArgs) |
static Object |
invokeMethod(Object obj,
String methodName,
Object... params)
Get and invoke the target method from the given object with given parameters
|
static void |
logThreadInfo(org.slf4j.Logger log,
String title,
long minInterval)
Log the current thread stacks at INFO level.
|
static <T> T |
newInstance(Class<T> type,
Object... params) |
private static void |
printThreadInfo(PrintStream stream,
String title)
Print all of the thread's information and stack traces.
|
private static long previousLogTime
private static final ThreadMXBean threadBean
public ReflectionUtils()
public static <T> T instantiateWithCustomCtor(String className, Class<?>[] ctorArgTypes, Object[] ctorArgs)
private static <T> T instantiate(String className, Constructor<T> ctor, Object[] ctorArgs)
public static <T> T newInstance(Class<T> type, Object... params)
public static <T> Constructor<T> findConstructor(Class<T> type, Object... paramTypes)
public static void logThreadInfo(org.slf4j.Logger log, String title, long minInterval)
log
- the logger that logs the stack tracetitle
- a descriptive title for the call stacksminInterval
- the minimum time from the lastprivate static void printThreadInfo(PrintStream stream, String title)
stream
- the stream totitle
- a string title for the stack traceprivate static String getTaskName(long id, String name)
@NonNull public static Object invokeMethod(Object obj, String methodName, Object... params)
obj
- the object to get and invoke method frommethodName
- the name of the method to invokeparams
- the parameters for the method to invokeprivate static Class<?>[] getParameterTypes(Object[] params)
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.