<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
On 06/02/2024 08:49, Danish Nawab wrote:<br>
<blockquote type="cite" cite="mid:MW4PR14MB6095CFBB79EDABECF8593FF4C3462@MW4PR14MB6095.namprd14.prod.outlook.com">
<style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>:
<div class="elementToProof"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
</span></div>
<div class="elementToProof"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">I
ask because, in the absence of a thread name, the
observability of the application suffers. Popular libraries
like logback only include the thread name (by default) in the
logs which makes the log messages less useful depending on the
issue to debug. Similarly, thread dumps don't contain thread
names anymore.</span></div>
<div class="elementToProof"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Of
course, virtual threads do have a
</span><code>threadId</code><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"> but
that is not as discoverable as the name.</span></div>
<br>
</blockquote>
This has come up a few times, you'll need to go through the archives
to see previous discussions on the topic.<br>
<br>
To summarize: Virtual threads are intended to be low footprint so
they don't get an automatically generated name by default. They have
a thread ID of course and that thread ID is in the string
representation and is readily available to logging libraries with
Thread::threadId. Virtual threads can be named where it makes sense.
In an application with thousands of virtual threads then it may be
useful to name a few special threads, like the thread that is
accepting connections but less useful to name the 10_000 threads in
the same "job role" handling a specific request. Thread dumps
include the thread ID for each thread and will include the names of
threads have have been given a name.<br>
<br>
I assume you've already found that you can name threads with the
Thread.Builder API and this includes auto-numbering. Many frameworks
and libraries use a ThreadFactory to create unstarted threads and
that can be used to put initial names on virtual threads too.<br>
<br>
-Alan<br>
</body>
</html>