public String getThreadsStacktraces(Collection<Long> ids) {
    StringBuilder errBuilder = new StringBuilder();
      for (long id : ids) {
        ThreadInfo ti = mbean.getThreadInfo(id, MAX_STACK_DEPTH);
        errBuilder.append("Deadlocked Thread:\n").
                append("------------------\n").
                append(ti).append('\n');
        for (StackTraceElement ste : ti.getStackTrace()) {
          errBuilder.append('\t').append(ste);
        }
        errBuilder.append('\n');
      }
    return errBuilder.toString();
  }
Monitoring of deadlocks thread
Please note. This class can not be used outside of tests
ambari-server/src/test/java/org/apache/ambari/server/testing/DeadlockWarningThread.java