Untitled
private static String getMethodNameFromBatchBase() { StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); String callerClass = stackTrace[3].getClassName(); try { Class<?> clazz = Class.forName(callerClass); // Iterate through the class hierarchy to find the first subclass of BatchBase while (clazz != null) { if (BatchBase.class.isAssignableFrom(clazz)) { // Return the method name from the BatchBase class StackTraceElement[] batchBaseStackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement element : batchBaseStackTrace) { if (element.getClassName().equals(clazz.getName())) { return element.getMethodName(); } } } clazz = clazz.getSuperclass(); // Move up the class hierarchy } } catch (ClassNotFoundException e) { e.printStackTrace(); } return getCallerMethodName(); // Fallback to the method name if no subclass is found }
Leave a Comment