Make forking task runner have more informative thread names during the long-blocking part (#3172)

* Make forking task runner have more informative thread names during the long-blocking part

* Make string.format do the work
This commit is contained in:
Charles Allen 2016-06-24 08:56:01 -07:00 committed by Gian Merlino
parent 15f833a861
commit 6be18376c0
1 changed files with 6 additions and 0 deletions

View File

@ -428,6 +428,11 @@ public class ForkingTaskRunner implements TaskRunner, TaskLogStreamer
boolean runFailed = true; boolean runFailed = true;
final ByteSink logSink = Files.asByteSink(logFile, FileWriteMode.APPEND); final ByteSink logSink = Files.asByteSink(logFile, FileWriteMode.APPEND);
// This will block for a while. So we append the thread information with more details
final String priorThreadName = Thread.currentThread().getName();
Thread.currentThread().setName(String.format("%s-[%s]", priorThreadName, task.getId()));
try (final OutputStream toLogfile = logSink.openStream()) { try (final OutputStream toLogfile = logSink.openStream()) {
ByteStreams.copy(processHolder.process.getInputStream(), toLogfile); ByteStreams.copy(processHolder.process.getInputStream(), toLogfile);
final int statusCode = processHolder.process.waitFor(); final int statusCode = processHolder.process.waitFor();
@ -437,6 +442,7 @@ public class ForkingTaskRunner implements TaskRunner, TaskLogStreamer
} }
} }
finally { finally {
Thread.currentThread().setName(priorThreadName);
// Upload task logs // Upload task logs
taskLogPusher.pushTaskLog(task.getId(), logFile); taskLogPusher.pushTaskLog(task.getId(), logFile);
} }