private void printThreadStats ( final HttpQuery query ) { final Set < Thread > threads = Thread . getAllStackTraces ( ) . keySet ( ) ; final List < Map < String , Object > > output = new ArrayList < Map < String , Object > > ( threads . size ( ) ) ; for ( final Thread thread : threads ) { final Map < String , Object > status = new HashMap < String , Object > ( ) ; status . put ( "threadID" , thread . getId ( ) ) ; status . put ( "name" , thread . getName ( ) ) ; status . put ( "state" , thread . getState ( ) . toString ( ) ) ; status . put ( "interrupted" , thread . isInterrupted ( ) ) ; status . put ( "priority" , thread . getPriority ( ) ) ; final List < String > stack = new ArrayList < String > ( thread . getStackTrace ( ) . length ) ; for ( final StackTraceElement element : thread . getStackTrace ( ) ) { stack . add ( element . toString ( ) ) ; } status . put ( "stack" , stack ) ; output . add ( status ) ; } query . sendReply ( query . serializer ( ) . formatThreadStatsV1 ( output ) ) ; }
Grabs a snapshot of all JVM thread states and formats it in a manner to be displayed via API .