Example usage for java.lang Thread.State toString

List of usage examples for java.lang Thread.State toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of this thread, including the thread's name, priority, and thread group.

Usage

From source file:serposcope.controllers.admin.AdminController.java

public Result stackdump(Context context) {

    return Results.contentType("text/plain").render((ctx, res) -> {
        ResponseStreams responseStreams = context.finalizeHeaders(res);
        try (PrintWriter writer = new PrintWriter(responseStreams.getOutputStream());) {
            final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
            final ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
            for (ThreadInfo threadInfo : threadInfos) {
                writer.append('"');
                writer.append(threadInfo.getThreadName());
                writer.append("\" ");
                final Thread.State state = threadInfo.getThreadState();
                writer.append("\n   java.lang.Thread.State: ");
                writer.append(state.toString());
                final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace();
                for (final StackTraceElement stackTraceElement : stackTraceElements) {
                    writer.append("\n        at ");
                    writer.append(stackTraceElement.toString());
                }//from w  ww.  ja v a  2 s  .  co m
                writer.println("\n");
            }
        } catch (IOException ex) {
            LOG.error("stackdump", ex);
        }
    });
}