Skip to content

Commit

Permalink
comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
henningandersen committed May 23, 2024
1 parent ef2a6a4 commit a7b6a85
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ public static String threadName(final String nodeName, final String namePrefix)

// to be used in assertions only.
public static boolean differentExecutors(Thread thread1, Thread thread2) {
assert thread1 != thread2 : "only call for different threads";
// this should only be used to validate thread interactions, like not waiting for a future completed on the same
// executor, hence calling it with the same thread indicates a bug in the assertion using this.
assert thread1 != thread2 : "only call this for different threads";
String thread1Name = executorName(thread1);
String thread2Name = executorName(thread2);
return thread1Name == null || thread2Name == null || thread1Name.equals(thread2Name) == false;
Expand All @@ -277,6 +279,7 @@ public static boolean differentExecutors(Thread thread1, Thread thread2) {
// visible for tests
static String executorName(Thread thread) {
String name = thread.getName();
// subtract 2 to avoid the `]` of the thread number part.
int executorNameEnd = name.lastIndexOf(']', name.length() - 2);
int executorNameStart = name.lastIndexOf('[', executorNameEnd);
if (executorNameStart == -1 || executorNameEnd - executorNameStart <= 1) {
Expand Down

0 comments on commit a7b6a85

Please sign in to comment.