[
https://issues.apache.org/jira/browse/HADOOP-13762?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15612440#comment-15612440
]
Chris Nauroth commented on HADOOP-13762:
----------------------------------------
Yes, you can change the thread name at any time. The thread name acts somewhat
like a mutable thread-local variable, accessed via
[{{Thread#getName()}}|http://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#getName--]
and
[{{Thread#setName(String)}}|http://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#setName-java.lang.String-].
We have some existing precedent for this in the DataNode, where we set the
{{DataXceiver}} threads with information about the specific data transfer
protocol method call and the block ID:
{code}
@Override
public void readBlock(final ExtendedBlock block,
final Token<BlockTokenIdentifier> blockToken,
final String clientName,
final long blockOffset,
final long length,
final boolean sendChecksum,
final CachingStrategy cachingStrategy) throws IOException {
previousOpClientName = clientName;
long read = 0;
updateCurrentThreadName("Sending block " + block);
...
{code}
{code}
/**
* Update the current thread's name to contain the current status.
* Use this only after this receiver has started on its thread, i.e.,
* outside the constructor.
*/
private void updateCurrentThreadName(String status) {
StringBuilder sb = new StringBuilder();
sb.append("DataXceiver for client ");
if (previousOpClientName != null) {
sb.append(previousOpClientName).append(" at ");
}
sb.append(remoteAddress);
if (status != null) {
sb.append(" [").append(status).append("]");
}
Thread.currentThread().setName(sb.toString());
}
{code}
I've never observed changing the thread name to cause any significant cost. It
would be good to watch out for the same pitfalls as logging, such as avoiding
calls to expensive {{toString}} implementations with a lot of string
concatenation in a tight loop.
> S3A: Set thread names with more specific information about the call.
> --------------------------------------------------------------------
>
> Key: HADOOP-13762
> URL: https://issues.apache.org/jira/browse/HADOOP-13762
> Project: Hadoop Common
> Issue Type: Sub-task
> Components: fs/s3
> Reporter: Chris Nauroth
>
> Running {{jstack}} on a hung process and reading the stack traces is a
> helpful way to determine exactly what code in the process is stuck. This
> would be even more helpful if we included more descriptive information about
> the specific file system method call.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]