Example usage for java.lang Thread getStackTrace

List of usage examples for java.lang Thread getStackTrace

Introduction

In this page you can find the example usage for java.lang Thread getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Returns an array of stack trace elements representing the stack dump of this thread.

Usage

From source file:org.jboss.dashboard.profiler.ThreadProfile.java

public static String printStackTrace(Thread t, int lines) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    pw.println("'" + t.getName() + "' '" + t.getState().toString() + "' ");
    StackTraceElement[] trace = t.getStackTrace();
    for (int i = 0; i < trace.length && i < lines; i++) {
        pw.println("\tat " + trace[i]);
    }// w  w  w .ja  v a  2 s .c o  m
    return sw.toString();
}

From source file:com.buaa.cfs.utils.StringUtils.java

/**
 * Get stack trace for a given thread.//from w ww .  j a  v  a2s .c o  m
 */
public static String getStackTrace(Thread t) {
    final StackTraceElement[] stackTrace = t.getStackTrace();
    StringBuilder str = new StringBuilder();
    for (StackTraceElement e : stackTrace) {
        str.append(e.toString() + "\n");
    }
    return str.toString();
}

From source file:org.hillview.utils.HillviewLogger.java

private String createMessage(String message, String format, Object... arguments) {
    message = this.checkCommas(message);
    String text = MessageFormat.format(format, arguments);
    Thread current = Thread.currentThread();
    StackTraceElement[] stackTraceElements = current.getStackTrace();
    StackTraceElement caller = stackTraceElements[3];
    String quoted = this.quote(text);
    return String.join(",", current.getName(), caller.getClassName(), caller.getMethodName(), message, quoted);
}

From source file:com.kotcrab.vis.editor.util.vis.CrashReporter.java

private void printThreadInfo() {
    println("--- Threads ---");

    Set<Thread> threadSet = Thread.getAllStackTraces().keySet();

    for (Thread t : threadSet) {
        println("Thread: " + t.getName() + ", daemon: " + t.isDaemon() + ", state: " + t.getState());
        for (StackTraceElement e : t.getStackTrace()) {
            crashReport.append("\t");
            println(e.toString());//  w w w.jav a 2  s  .c  o  m
        }

        println();
    }

    println("---------------");
    println();
}

From source file:com.kotcrab.vis.editor.util.CrashReporter.java

private void printThreadInfo() {
    println("--- Threads ---");

    Set<Thread> threadSet = Thread.getAllStackTraces().keySet();

    for (Thread t : threadSet) {
        if (t.isDaemon()) {
            println("Skipping daemon thread: " + t.getName());
        } else {/*from   w w w  . j ava 2 s  .c  o  m*/
            println("Thread: " + t.getName());
            for (StackTraceElement e : t.getStackTrace()) {
                crashReport.append("\t");
                println(e.toString());
            }
        }

        println();
    }

    println("---------------");
    println();
}

From source file:org.bonitasoft.engine.LocalServerTestsInitializer.java

private void printThread(final Thread thread) {
    System.out.println("\n");
    System.out.println("Thread is still alive:" + thread.getName());
    for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
        System.out.println("        at " + stackTraceElement.toString());
    }/*from   w  ww.  ja v a 2  s .co  m*/
}

From source file:org.bonitasoft.engine.test.internal.EngineStarter.java

private void printThread(final Thread thread) {
    LOGGER.info("\n");
    LOGGER.info("Thread is still alive:" + thread.getName());
    for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
        LOGGER.info("        at " + stackTraceElement.toString());
    }/*from  w w  w.ja va  2s  .c om*/
}

From source file:Parallelizer.java

/**
 * Dump the stack of each running thread.
 * <p>/*from   w w w  . j  a  v a2s.c  o  m*/
 * If this method throws an error, that
 * error may be handled and this method
 * may be called again as it will not re-throw the same
 * instance of the error.
 *
 * @throws Error if any of the running threads has thrown an Error.
 *
 * @since ostermillerutils 1.05.00
 */
public void dumpStack() {
    throwFirstError();
    synchronized (runningThreads) {
        for (Thread thread : runningThreads) {
            for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
                System.out.println(stackTraceElement.toString());
            }
            throwFirstError();
        }
    }
}

From source file:com.gargoylesoftware.htmlunit.SimpleWebTestCase.java

/**
 * Cleanup after a test.//w  w  w  .  j  a  v a 2s .  c  o m
 */
@After
public void releaseResources() {
    super.releaseResources();
    if (webClient_ != null) {
        webClient_.closeAllWindows();
        webClient_.getCookieManager().clearCookies();
    }
    webClient_ = null;

    final List<Thread> jsThreads = getJavaScriptThreads();
    // collect stack traces
    // caution: the threads may terminate after the threads have been returned by getJavaScriptThreads()
    // and before stack traces are retrieved
    if (jsThreads.size() > nbJSThreadsBeforeTest_) {
        final Map<String, StackTraceElement[]> stackTraces = new HashMap<String, StackTraceElement[]>();
        for (final Thread t : jsThreads) {
            final StackTraceElement elts[] = t.getStackTrace();
            if (elts != null) {
                stackTraces.put(t.getName(), elts);
            }
        }

        if (!stackTraces.isEmpty()) {
            System.err.println("JS threads still running:");
            for (final Map.Entry<String, StackTraceElement[]> entry : stackTraces.entrySet()) {
                System.err.println("Thread: " + entry.getKey());
                final StackTraceElement elts[] = entry.getValue();
                for (final StackTraceElement elt : elts) {
                    System.err.println(elt);
                }
            }
            throw new RuntimeException("JS threads are still running: " + jsThreads.size());
        }
    }
}

From source file:com.sonatype.nexus.perftest.ClientSwarm.java

public void stop() throws InterruptedException {
    for (Thread thread : threads) {
        for (int i = 0; i < 3 && thread.isAlive(); i++) {
            thread.interrupt();/*from  w w  w  .  j  ava 2  s. c  o  m*/
            thread.join(1000L);
        }
        if (thread.isAlive()) {
            StringBuilder sb = new StringBuilder(
                    String.format("Thread %s ignored interrupt flag\n", thread.getName()));
            for (StackTraceElement f : thread.getStackTrace()) {
                sb.append("\t").append(f.toString()).append("\n");
            }
            System.err.println(sb.toString());
        }
    }
}