{"id":6469,"date":"2017-10-23T13:16:51","date_gmt":"2017-10-23T18:16:51","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=6469"},"modified":"2017-10-23T13:16:51","modified_gmt":"2017-10-23T18:16:51","slug":"programatically-gathering-a-thread-dump","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2017\/10\/23\/programatically-gathering-a-thread-dump\/","title":{"rendered":"Programatically gathering a thread dump"},"content":{"rendered":"<p>This is just a method you could add to your software if you wish to trigger a thread dump in a controlled fashion.<\/p>\n<pre>\r\nimport java.sql.*;\r\nimport java.lang.management.*;\r\n\r\npublic class DebugLocks {\r\n  public static String dumpThreads() {\r\n    final StringBuilder dump = new StringBuilder();\r\n    final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();\r\n    final ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);\r\n    for (ThreadInfo threadInfo : threadInfos) {\r\n      dump.append('\"');\r\n      dump.append(threadInfo.getThreadName() + \"(\" + threadInfo.getThreadId() + \")\");\r\n      dump.append(\"\\\" \");\r\n      final Thread.State state = threadInfo.getThreadState();\r\n      dump.append(\"\\n   java.lang.Thread.State: \");\r\n      dump.append(state);\r\n      final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace();\r\n      for (final StackTraceElement stackTraceElement : stackTraceElements) {\r\n        dump.append(\"\\n        at \");\r\n        dump.append(stackTraceElement);\r\n      }\r\n      dump.append(\"\\n\\n\");\r\n    }\r\n    return dump.toString();\r\n  }\r\n  public static void main (String args[]) throws Exception {\r\n    System.out.println(dumpThreads());\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is just a method you could add to your software if you wish to trigger a thread dump in a controlled fashion. import java.sql.*; import java.lang.management.*; public class DebugLocks { public static String dumpThreads() { final StringBuilder dump =&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2017\/10\/23\/programatically-gathering-a-thread-dump\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[7],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6469"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=6469"}],"version-history":[{"count":2,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6469\/revisions"}],"predecessor-version":[{"id":6471,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6469\/revisions\/6471"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6469"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}