code: public static String getFormattedDeadlockInfo(
        final String prefix, final String threadPrefix, final String stackElementPrefix) {
      final StringBuilder message = new StringBuilder(prefix);
  
      final DeadlockInfo deadlockInfo = new DeadlockInfo();
  
      final ThreadInfo[] deadlockedThreads = deadlockInfo.getDeadlockedThreads();
  
      if (0 == deadlockedThreads.length) {
        message.append(" none ");
        return message.toString();
      }
  
      for (final ThreadInfo threadInfo : deadlockedThreads) {
        message.append(threadPrefix).append("Thread '").append(threadInfo.getThreadName())
            .append("' with state ").append(threadInfo.getThreadState());
  
        boolean firstElement = true;
        for (final StackTraceElement stackTraceElement : threadInfo.getStackTrace()) {
          message.append(stackElementPrefix).append("at ").append(stackTraceElement);
          if (firstElement) {
            final String waitingLockString = deadlockInfo.getWaitingLockString(threadInfo);
            if (waitingLockString != null) {
              message.append(stackElementPrefix).append("- waiting to lock: ").append(waitingLockString);
            }
            firstElement = false;
          }
          for (final MonitorInfo info : deadlockInfo.getMonitorLockedElements(threadInfo, stackTraceElement)) {
            message.append(stackElementPrefix).append("- locked: ").append(info);
          }
        }
        for (final LockInfo lockInfo : threadInfo.getLockedSynchronizers()) {
          message.append(stackElementPrefix).append("* holds locked synchronizer: ").append(lockInfo);
        }
      }
  
      return message.toString();
    }
docs: Produces a String representation of threads that are deadlocked, including lock information.
  @param prefix             The prefix of the string returned.
  @param threadPrefix       Printed before each thread, e.g. "\n\t" to create an indented list.
  @param stackElementPrefix Printed before each stack trace element, e.g. "\n\t\t" to create an indented list.
  @return a String representation of threads that are deadlocked, including lock information