public Set < String > getDeadlockedThreads ( ) { final long [ ] threadIds = threads . findDeadlockedThreads ( ) ; if ( threadIds != null ) { final Set < String > threads = new HashSet < String > ( ) ; for ( ThreadInfo info : this . threads . getThreadInfo ( threadIds , MAX_STACK_TRACE_DEPTH ) ) { final StringBuilder stackTrace = new StringBuilder ( ) ; for ( StackTraceElement element : info . getStackTrace ( ) ) { stackTrace . append ( "\t at " ) . append ( element . toString ( ) ) . append ( ' ' ) ; } threads . add ( String . format ( "%s locked on %s (owned by %s):\n%s" , info . getThreadName ( ) , info . getLockName ( ) , info . getLockOwnerName ( ) , stackTrace . toString ( ) ) ) ; } return Collections . unmodifiableSet ( threads ) ; } return Collections . emptySet ( ) ; }
Returns a set of strings describing deadlocked threads if any are deadlocked .