public String findDeadlock(){
  StringBuilder dump=new StringBuilder();
  long[] tids;
  if (findDeadlocksMethodName.equals("findDeadlockedThreads") && tmbean.isSynchronizerUsageSupported()) {
    tids=tmbean.findDeadlockedThreads();
    if (tids == null) {
      return null;
    }
    dump.append("\n\nFound one Java-level deadlock:\n");
    dump.append("==============================\n");
    ThreadInfo[] infos=tmbean.getThreadInfo(tids,true,true);
    for (int i=1; i < infos.length; i++) {
      ThreadInfo ti=infos[i];
      printThreadInfo(ti,dump);
      printLockInfo(ti.getLockedSynchronizers(),dump);
      dump.append("\n");
    }
  }
 else {
    tids=tmbean.findMonitorDeadlockedThreads();
    if (tids == null) {
      return null;
    }
    dump.append("\n\nFound one Java-level deadlock:\n");
    dump.append("==============================\n");
    ThreadInfo[] infos=tmbean.getThreadInfo(tids,Integer.MAX_VALUE);
    for (int i=1; i < infos.length; i++) {
      ThreadInfo ti=infos[i];
      printThreadInfo(ti,dump);
    }
  }
  return (dump.toString());
}

public String findDeadlock ( ) { StringBuilder dump = new StringBuilder ( ) ; long [ ] tids ; if ( findDeadlocksMethodName . equals ( "findDeadlockedThreads" ) && tmbean . isSynchronizerUsageSupported ( ) ) { tids = tmbean . findDeadlockedThreads ( ) ; if ( tids == null ) { return null ; } dump . append ( "\n\nFound one Java-level deadlock:\n" ) ; dump . append ( "==============================\n" ) ; ThreadInfo [ ] infos = tmbean . getThreadInfo ( tids , true , true ) ; for ( int i = 1 ; i < infos . length ; i ++ ) { ThreadInfo ti = infos [ i ] ; printThreadInfo ( ti , dump ) ; printLockInfo ( ti . getLockedSynchronizers ( ) , dump ) ; dump . append ( "\n" ) ; } } else { tids = tmbean . findMonitorDeadlockedThreads ( ) ; if ( tids == null ) { return null ; } dump . append ( "\n\nFound one Java-level deadlock:\n" ) ; dump . append ( "==============================\n" ) ; ThreadInfo [ ] infos = tmbean . getThreadInfo ( tids , Integer . MAX_VALUE ) ; for ( int i = 1 ; i < infos . length ; i ++ ) { ThreadInfo ti = infos [ i ] ; printThreadInfo ( ti , dump ) ; } } return ( dump . toString ( ) ) ; }
checks if any threads are deadlocked . if any , print the thread dump information .
