code: public void findDeadlockedThreads ()
    {
      final long [] aThreadIDs = m_aMBean.isSynchronizerUsageSupported () ? m_aMBean.findDeadlockedThreads ()
                                                                          : m_aMBean.findMonitorDeadlockedThreads ();
      if (ArrayHelper.isNotEmpty (aThreadIDs))
      {
        // Get all stack traces
        final Map <Thread, StackTraceElement []> aAllStackTraces = Thread.getAllStackTraces ();
  
        // Sort by ID for a consistent result
        Arrays.sort (aThreadIDs);
  
        // Extract the relevant information
        final ThreadDeadlockInfo [] aThreadInfos = new ThreadDeadlockInfo [aThreadIDs.length];
        for (int i = 0; i < aThreadInfos.length; i++)
        {
          // ThreadInfo
          final ThreadInfo aThreadInfo = m_aMBean.getThreadInfo (aThreadIDs[i]);
  
          // Find matching thread and stack trace
          Thread aFoundThread = null;
          StackTraceElement [] aFoundStackTrace = null;
          // Sort ascending by thread ID for a consistent result
          for (final Map.Entry <Thread, StackTraceElement []> aEnrty : aAllStackTraces.entrySet ())
            if (aEnrty.getKey ().getId () == aThreadInfo.getThreadId ())
            {
              aFoundThread = aEnrty.getKey ();
              aFoundStackTrace = aEnrty.getValue ();
              break;
            }
          if (aFoundThread == null)
            throw new IllegalStateException ("Deadlocked Thread not found as defined by " + aThreadInfo.toString ());
  
          // Remember
          aThreadInfos[i] = new ThreadDeadlockInfo (aThreadInfo, aFoundThread, aFoundStackTrace);
        }
  
        // Invoke all callbacks
        if (m_aCallbacks.isEmpty ())
        {
          if (LOGGER.isWarnEnabled ())
            LOGGER.warn ("Found a deadlock of " + aThreadInfos.length + " threads but no callbacks are present!");
        }
        else
          m_aCallbacks.forEach (x -> x.onDeadlockDetected (aThreadInfos));
      }
    }
docs: This is the main method to be invoked to find deadlocked threads. In case a
  deadlock is found, all registered callbacks are invoked.