Here you can find the source of getStackTraceString()
private static final synchronized String getStackTraceString()
//package com.java2s; /*/* w w w .j a v a 2 s. co m*/ * $Id$ * (c) Copyright 2000 wingS development team. * * This file is part of wingS (http://j-wings.org). * * wingS is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 * of the License, or (at your option) any later version. * * Please see COPYING for the complete licence. */ import java.io.StringWriter; import java.io.PrintWriter; public class Main { private static final StringWriter STACK_TRACE_STRING_WRITER = new StringWriter(); private static final PrintWriter STACK_TRACE_PRINT_WRITER = new PrintWriter(STACK_TRACE_STRING_WRITER); private static final Throwable STACK_TRACE_EXCEPTION = new Throwable(); private static final synchronized String getStackTraceString() { return getStackTraceString(STACK_TRACE_EXCEPTION.fillInStackTrace()); // kann sein, dass das schneller ist (vor allem mit JIT), verbraucht aber // sicher mehr Resourcen //return getStackTraceString(new Throwable()); } public static final synchronized String getStackTraceString(Throwable e) { STACK_TRACE_STRING_WRITER.getBuffer().setLength(0); e.printStackTrace(STACK_TRACE_PRINT_WRITER); return STACK_TRACE_STRING_WRITER.toString(); } }