ThreadState (List<? extends ThreadState> result, @Nullable String lockId, boolean ignoreWaiting) { if (lockId == null) return null; final String marker = "- locked <" + lockId + ">"; for(ThreadState lockOwner : result) { String trace = lockOwner.getStackTrace(); if (trace.contains(marker) && (!ignoreWaiting || !trace.contains(AT_JAVA_LANG_OBJECT_WAIT))) { return lockOwner; } } return null; }