<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Javadoc</span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"> [1]</span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);"> </span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">has
the following to say about virtual threads:</span></div>
<p class="elementToProof" style="margin-top: 0px; margin-bottom: 0px;"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">>
</span><span style="font-family: "DejaVu Serif", Georgia, "Times New Roman", Times, serif; font-size: 14px; color: rgb(71, 71, 71);">Virtual threads do not have a thread name by default. The
</span><span style="font-family: var(--code-font-family); font-size: var(--code-font-size); line-height: 1.4em;"><code style="font-family: var(--code-font-family);"><a href="https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Thread.html#getName()" id="OWA3556a420-4e27-85a8-cdb0-52d298505d4e" class="OWAAutoLink" style="text-decoration: none; margin-top: 0px; margin-bottom: 0px;">getName</a></code></span><span style="font-family: "DejaVu Serif", Georgia, "Times New Roman", Times, serif; font-size: 14px; color: rgb(71, 71, 71);"> method
returns the empty string if a thread name is not set.</span></p>
<div><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);">What's the reason for this difference between platform and virtual threads? Is this because virtual threads need to be so cheap and
lightweight to create and retain that the performance hit incurred when creating a name (an
</span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">atomic add and a string concat [2]</span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">) is
deemed unacceptable? </span></div>
<div class="elementToProof"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">The resulting string will also occupy some heap space (which might not be that big of a problem considering the recommended use of virtual
threads is to "</span><span style="font-family: "DejaVu Sans", "Bitstream Vera Sans", "Luxi Sans", Verdana, Arial, Helvetica; font-size: 13.3333px; color: rgb(0, 0, 0);">be short-lived and have shallow call stacks</span><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">"
[3]).</span></div>
<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>
<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);">This puts the onus on the users of virtual threads (often frameworks and libraries) to name their virtual threads [4] [5]. This of course
begs the question of what downsides (performance hits etc.) these libraries will impose on their users by naming virtual threads when the JDK decided not to do so. </span></div>
<div class="elementToProof"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Stating the reasons why this decision was made (and will be retained?) would help the community decide what the best course of action
is here.</span></div>
<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);">[1]
<a href="https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Thread.html" id="LPlnk" class="OWAAutoLink">
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Thread.html</a> </span></div>
<div class="elementToProof"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">[2]
<a href="https://github.com/openjdk/jdk21/blob/master/src/java.base/share/classes/java/lang/ThreadBuilders.java#L315-L321" id="LPlnk343087" class="OWAAutoLink">
https://github.com/openjdk/jdk21/blob/master/src/java.base/share/classes/java/lang/ThreadBuilders.java#L315-L321</a></span></div>
<div class="elementToProof"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">[3]
<a href="https://openjdk.org/jeps/444" id="LPlnk303126" class="OWAAutoLink">https://openjdk.org/jeps/444</a></span></div>
<div class="elementToProof"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">[4]
<a href="https://github.com/jetty/jetty.project/issues/11353" id="LPlnk" class="OWAAutoLink">
https://github.com/jetty/jetty.project/issues/11353</a></span></div>
<div class="elementToProof"><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">[5]
<a href="https://github.com/apache/tomcat/blob/main/java/org/apache/tomcat/util/threads/VirtualThreadExecutor.java#L40" id="LPlnk723930" class="OWAAutoLink">
https://github.com/apache/tomcat/blob/main/java/org/apache/tomcat/util/threads/VirtualThreadExecutor.java#L40</a></span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
</body>
</html>