@edu.umd.cs.findbugs.annotations.SuppressWarnings(
            value = {"VA_FORMAT_STRING_USES_NEWLINE"},
            justification = "We don't want platform specific"
    )
    public static void printThreadInfo(PrintWriter writer, ThreadInfo t, ThreadMXBean mbean) {
        long cpuPercentage;
        try {
            long cpuTime = mbean.getThreadCpuTime(t.getThreadId());
            long threadUserTime = mbean.getThreadUserTime(t.getThreadId());
            cpuPercentage = (cpuTime == 0) ? 0: 100 * threadUserTime / cpuTime;
        } catch (UnsupportedOperationException x) {
            SupportLogFormatter.printStackTrace(x, writer);
            cpuPercentage = 0;
        }
        writer.printf("\"%s\" id=%d (0x%x) state=%s cpu=%d%%",
                t.getThreadName(),
                t.getThreadId(),
                t.getThreadId(),
                t.getThreadState(),
                cpuPercentage);
        final LockInfo lock = t.getLockInfo();
        if (lock != null && t.getThreadState() != Thread.State.BLOCKED) {
            writer.printf("\n    - waiting on <0x%08x> (a %s)",
                    lock.getIdentityHashCode(),
                    lock.getClassName());
            writer.printf("\n    - locked <0x%08x> (a %s)",
                    lock.getIdentityHashCode(),
                    lock.getClassName());
        } else if (lock != null && t.getThreadState() == Thread.State.BLOCKED) {
            writer.printf("\n    - waiting to lock <0x%08x> (a %s)",
                    lock.getIdentityHashCode(),
                    lock.getClassName());
        }

        if (t.isSuspended()) {
            writer.print(" (suspended)");
        }

        if (t.isInNative()) {
            writer.print(" (running in native)");
        }

        writer.println();
        if (t.getLockOwnerName() != null) {
            writer.printf("      owned by \"%s\" id=%d (0x%x)\n",
                    t.getLockOwnerName(),
                    t.getLockOwnerId(),
                    t.getLockOwnerId());
        }

        final StackTraceElement[] elements = t.getStackTrace();
        final MonitorInfo[] monitors = t.getLockedMonitors();

        for (int i = 0; i < elements.length; i++) {
            final StackTraceElement element = elements[i];
            writer.printf("    at %s\n", element);
            for (int j = 1; j < monitors.length; j++) {
                final MonitorInfo monitor = monitors[j];
                if (monitor.getLockedStackDepth() == i) {
                    writer.printf("      - locked %s\n", monitor);
                }
            }
        }
        writer.println();

        final LockInfo[] locks = t.getLockedSynchronizers();
        if (locks.length > 0) {
            writer.printf("    Locked synchronizers: count = %d\n", locks.length);
            for (LockInfo l : locks) {
                writer.printf("      - %s\n", l);
            }
            writer.println();
        }
    }
@ edu . umd . cs . findbugs . annotations . SuppressWarnings ( value = { "VA_FORMAT_STRING_USES_NEWLINE" } , justification = "We don't want platform specific" ) public static void printThreadInfo ( PrintWriter writer , ThreadInfo t , ThreadMXBean mbean ) { long cpuPercentage ; try { long cpuTime = mbean . getThreadCpuTime ( t . getThreadId ( ) ) ; long threadUserTime = mbean . getThreadUserTime ( t . getThreadId ( ) ) ; cpuPercentage = ( cpuTime == 0 ) ? 0 : 100 * threadUserTime / cpuTime ; } catch ( UnsupportedOperationException x ) { SupportLogFormatter . printStackTrace ( x , writer ) ; cpuPercentage = 0 ; } writer . printf ( "\"%s\" id=%d (0x%x) state=%s cpu=%d%%" , t . getThreadName ( ) , t . getThreadId ( ) , t . getThreadId ( ) , t . getThreadState ( ) , cpuPercentage ) ; final LockInfo lock = t . getLockInfo ( ) ; if ( lock != null && t . getThreadState ( ) != Thread . State . BLOCKED ) { writer . printf ( "\n    - waiting on <0x%08x> (a %s)" , lock . getIdentityHashCode ( ) , lock . getClassName ( ) ) ; writer . printf ( "\n    - locked <0x%08x> (a %s)" , lock . getIdentityHashCode ( ) , lock . getClassName ( ) ) ; } else if ( lock != null && t . getThreadState ( ) == Thread . State . BLOCKED ) { writer . printf ( "\n    - waiting to lock <0x%08x> (a %s)" , lock . getIdentityHashCode ( ) , lock . getClassName ( ) ) ; } if ( t . isSuspended ( ) ) { writer . print ( " (suspended)" ) ; } if ( t . isInNative ( ) ) { writer . print ( " (running in native)" ) ; } writer . println ( ) ; if ( t . getLockOwnerName ( ) != null ) { writer . printf ( "      owned by \"%s\" id=%d (0x%x)\n" , t . getLockOwnerName ( ) , t . getLockOwnerId ( ) , t . getLockOwnerId ( ) ) ; } final StackTraceElement [ ] elements = t . getStackTrace ( ) ; final MonitorInfo [ ] monitors = t . getLockedMonitors ( ) ; for ( int i = 0 ; i < elements . length ; i ++ ) { final StackTraceElement element = elements [ i ] ; writer . printf ( "    at %s\n" , element ) ; for ( int j = 1 ; j < monitors . length ; j ++ ) { final MonitorInfo monitor = monitors [ j ] ; if ( monitor . getLockedStackDepth ( ) == i ) { writer . printf ( "      - locked %s\n" , monitor ) ; } } } writer . println ( ) ; final LockInfo [ ] locks = t . getLockedSynchronizers ( ) ; if ( locks . length > 0 ) { writer . printf ( "    Locked synchronizers: count = %d\n" , locks . length ) ; for ( LockInfo l : locks ) { writer . printf ( "      - %s\n" , l ) ; } writer . println ( ) ; } }
Prints the {@link ThreadInfo} (because {@link ThreadInfo#toString()} caps out the stack trace at 8 frames)

@param writer the writer to print to.
@param t      the thread to print
@param mbean  the {@link ThreadMXBean} to use.