Skip to content

Commit

Permalink
concurrent-api: save the timestamp of the SingleToFuture.get() calls (#…
Browse files Browse the repository at this point in the history
…3051)

Motivation:

It can be very difficult to know if a thread is slow or completely
stuck without taking multiple thread dumps and comparing them.

Modifications:

Try to mitigate this by saving the time stamp of the last blocking
`.get()` call. This should then show up in heap dumps and we can
at least compare them to see if they've all started blocking at
about the same time or if there is a big spread. The latter would
suggest they are truly stuck.
  • Loading branch information
bryce-anderson authored Sep 4, 2024
1 parent 338e52e commit 249efc7
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ abstract class SourceToFuture<T> implements Future<T> {
@Nullable
private volatile Object value;

// The timestamp of the last `.get()` call. This is intended to help with debugging stuck threads via heap dumps.
private long lastGetTimestampMs;

private SourceToFuture() {
}

Expand Down Expand Up @@ -91,7 +94,12 @@ public final boolean isDone() {
public final T get() throws InterruptedException, ExecutionException {
final Object value = this.value;
if (value == null) {
latch.await();
lastGetTimestampMs = System.currentTimeMillis();
try {
latch.await();
} finally {
lastGetTimestampMs = 0;
}
return reportGet(this.value);
} else {
return reportGet(value);
Expand Down

0 comments on commit 249efc7

Please sign in to comment.