Java tutorial
//package com.java2s; public class Main { public static String getThreadStack(Thread t) { StackTraceElement[] stacks = t.getStackTrace(); StringBuffer buffer = new StringBuffer(); for (StackTraceElement stack : stacks) { String filename = stack.getFileName(); if (filename == null) { filename = "NULL"; } String className = stack.getClassName(); String methodName = stack.getMethodName(); int line = stack.getLineNumber(); buffer.append(String.format("%s.%s(%s:%d)\r", className, methodName, filename, line)); } return buffer.toString(); } }