public static void threadDump(){
  LOG.error("All threads are in use. Logging the thread stack trace to threaddump.txt and exiting.");
  final ThreadMXBean threads=ManagementFactory.getThreadMXBean();
  long[] threadIds=threads.getAllThreadIds();
  PrintWriter printWriter=null;
  try {
    printWriter=new PrintWriter(new FileWriter(THREAD_DUMP_FILE_PATH,false));
    printWriter.println("Raptor ThreadService initiated dump " + new Date());
    for (    long threadId : threadIds) {
      ThreadInfo threadInfo=threads.getThreadInfo(threadId,10);
      printWriter.println("Thread " + threadInfo.getThreadName() + " Block time:"+ threadInfo.getBlockedTime()+ " Block count:"+ threadInfo.getBlockedCount()+ " Lock name:"+ threadInfo.getLockName()+ " Waited Count:"+ threadInfo.getWaitedCount()+ " Waited Time:"+ threadInfo.getWaitedTime()+ " Is Suspended:"+ threadInfo.isSuspended());
      StackTraceElement[] stackTrace=threadInfo.getStackTrace();
      for (      StackTraceElement element : stackTrace) {
        printWriter.println(element);
      }
    }
  }
 catch (  IOException ioe) {
    ioe.printStackTrace();
  }
 finally {
    if (printWriter != null) {
      try {
        printWriter.flush();
        printWriter.close();
      }
 catch (      Exception e2) {
      }
    }
  }
}

public static void threadDump ( ) { LOG . error ( "All threads are in use. Logging the thread stack trace to threaddump.txt and exiting." ) ; final ThreadMXBean threads = ManagementFactory . getThreadMXBean ( ) ; long [ ] threadIds = threads . getAllThreadIds ( ) ; PrintWriter printWriter = null ; try { printWriter = new PrintWriter ( new FileWriter ( THREAD_DUMP_FILE_PATH , false ) ) ; printWriter . println ( "Raptor ThreadService initiated dump " + new Date ( ) ) ; for ( long threadId : threadIds ) { ThreadInfo threadInfo = threads . getThreadInfo ( threadId , 10 ) ; printWriter . println ( "Thread " + threadInfo . getThreadName ( ) + " Block time:" + threadInfo . getBlockedTime ( ) + " Block count:" + threadInfo . getBlockedCount ( ) + " Lock name:" + threadInfo . getLockName ( ) + " Waited Count:" + threadInfo . getWaitedCount ( ) + " Waited Time:" + threadInfo . getWaitedTime ( ) + " Is Suspended:" + threadInfo . isSuspended ( ) ) ; StackTraceElement [ ] stackTrace = threadInfo . getStackTrace ( ) ; for ( StackTraceElement element : stackTrace ) { printWriter . println ( element ) ; } } } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } finally { if ( printWriter != null ) { try { printWriter . flush ( ) ; printWriter . close ( ) ; } catch ( Exception e2 ) { } } } }
dumps stack traces of all threads to threaddump . txt .
