标签:flow ble over pre target img hive org arc
转自:http://www.cnblogs.com/AloneSword/p/3857423.html
java 中可以通过 eclipse 等工具直接打印堆栈,但是对于某些环境中无法使用 eclipse 工具时,需要知道堆栈,如何处理呢?
介绍3种方法供选择:
方法一:
package name.xu;
public class CallStack {
public static void printCallStatck() {
Throwable ex = new Throwable();
StackTraceElement[] stackElements = ex.getStackTrace();
if (stackElements != null) {
for (int i = 0; i < stackElements.length; i++) {
System.out.print(stackElements[i].getClassName()+"/t");
System.out.print(stackElements[i].getFileName()+"/t");
System.out.print(stackElements[i].getLineNumber()+"/t");
System.out.println(stackElements[i].getMethodName());
System.out.println("-----------------------------------");
}
}
}
}
方法二:
Exception e = new Exception("this is a log");
e.printStackTrace();
方法三:
String fullStackTrace = org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(e)
方法四:
Thread.currentThread().getStackTrace()
个人推荐,方法一,原因:简单易用,速度快
参考资料:
1、http://blog.csdn.net/chief1985/article/details/4618492
2、http://www.cnblogs.com/flyme/archive/2012/04/10/2440029.html
3、http://stackoverflow.com/questions/1069066/get-current-stack-trace-in-java 【推荐仔细看看】
标签:flow ble over pre target img hive org arc
原文地址:http://www.cnblogs.com/dirt2/p/7351724.html