Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/virtual-threads.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ However, thread locals are not propagated.
== Virtual thread names

Virtual threads are created without a thread name by default, which is not practical to identify the execution for debugging and logging purposes.
Quarkus managed virtual threads are named and prefixed with `quarkus-virtual-thread-`.
Quarkus managed virtual threads are named with `quarkus-virtual-thread`.
You can customize this prefix, or disable the naming altogether configuring an empty value:

[source, properties]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
public interface VirtualThreadsConfig {

/**
* Virtual thread name prefix. The name of the virtual thread will be the prefix followed by a unique number.
* Virtual thread name. The name of the virtual thread will be the prefix.
*/
@WithDefault("quarkus-virtual-thread-")
@WithDefault("quarkus-virtual-thread")
Optional<String> namePrefix();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ static ExecutorService newVirtualThreadPerTaskExecutorWithName(String prefix)
Class<?> vtbClass = Class.forName("java.lang.Thread$Builder$OfVirtual");
// .name()
if (prefix != null) {
Method name = vtbClass.getMethod("name", String.class, long.class);
vtb = name.invoke(vtb, prefix, 0);
// why this is not using name(prefix, 0)?
// see https://bugs.openjdk.org/browse/JDK-8372410
Method name = vtbClass.getMethod("name", String.class);
vtb = name.invoke(vtb, prefix);
}
// .uncaughtExceptionHandler()
Method uncaughtHandler = vtbClass.getMethod("uncaughtExceptionHandler", Thread.UncaughtExceptionHandler.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class RunOnVirtualThreadTest {
.withApplicationRoot(root -> {
root.addClasses(Endpoint.class, WSClient.class, RequestScopedBean.class)
.addAsResource(new StringAsset(
"quarkus.virtual-threads.name-prefix=wsnext-virtual-thread-"),
"quarkus.virtual-threads.name-prefix=wsnext-virtual-thread"),
"application.properties");
});

Expand Down Expand Up @@ -82,7 +82,7 @@ public static class Endpoint {
@OnTextMessage
String text(String ignored) {
VirtualThreadsAssertions.assertEverything();
return Thread.currentThread().getName();
return Thread.currentThread().getName() + '-' + Thread.currentThread().getId();
}

@OnError
Expand All @@ -102,13 +102,13 @@ public static class EndpointVirtOnClass {
@OnOpen
String open() {
VirtualThreadsAssertions.assertEverything();
return Thread.currentThread().getName();
return Thread.currentThread().getName() + '-' + Thread.currentThread().getId();
}

@OnTextMessage
String text(String ignored) {
VirtualThreadsAssertions.assertEverything();
return Thread.currentThread().getName();
return Thread.currentThread().getName() + '-' + Thread.currentThread().getId();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void assertThatTheBinderIsAvailable() {
String hello() {
assertThatTheBinderIsAvailable();
VirtualThreadsAssertions.assertEverything();
// Quarkus specific - each VT has a unique name
return Thread.currentThread().getName();
// Quarkus specific - all VTs shares the same prefix
return Thread.currentThread().getName() + '-' + Thread.currentThread().getId();
}

@Route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static io.restassured.RestAssured.get;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

Expand All @@ -18,8 +18,9 @@ class RunOnVirtualThreadTest {
@Test
void testRouteOnVirtualThread() {
String bodyStr = get("/hello").then().statusCode(200).extract().asString();
// Each VT has a unique name in quarkus
assertNotEquals(bodyStr, get("/hello").then().statusCode(200).extract().asString());
// Quarkus specific - all VTs shares the same prefix
assertTrue(bodyStr.startsWith("quarkus-virtual-thread"));
assertTrue(get("/hello").then().statusCode(200).extract().asString().startsWith("quarkus-virtual-thread"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void init(@Observes StartupEvent ev, Scheduler scheduler) {
.setInterval("1s")
.setTask(ex -> {
VirtualThreadsAssertions.assertEverything();
// Quarkus specific - each VT has a unique name
programmaticExecutions.add(Thread.currentThread().getName());
// Quarkus specific - all VTs shares the same prefix
programmaticExecutions.add(Thread.currentThread().getName() + '-' + Thread.currentThread().getId());
}, true)
.schedule();
}
Expand All @@ -34,8 +34,8 @@ public void init(@Observes StartupEvent ev, Scheduler scheduler) {
@RunOnVirtualThread
void run() {
VirtualThreadsAssertions.assertEverything();
// Quarkus specific - each VT has a unique name
executions.add(Thread.currentThread().getName());
// Quarkus specific - all VTs shares the same prefix
executions.add(Thread.currentThread().getName() + '-' + Thread.currentThread().getId());
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class Routes {
@Route
String hello() {
VirtualThreadsAssertions.assertEverything();
// Quarkus specific - each VT has a unique name
return Thread.currentThread().getName();
// Quarkus specific - all VTs shares the same prefix
return Thread.currentThread().getName() + '-' + Thread.currentThread().getId();
}

@Route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void init(@Observes StartupEvent ev, Scheduler scheduler) {
.setInterval("1s")
.setTask(ex -> {
VirtualThreadsAssertions.assertEverything();
// Quarkus specific - each VT has a unique name
programmaticExecutions.add(Thread.currentThread().getName());
// Quarkus specific - all VTs shares the same prefix
programmaticExecutions.add(Thread.currentThread().getName() + '-' + Thread.currentThread().getId());
}, true)
.schedule();
}
Expand All @@ -34,8 +34,8 @@ public void init(@Observes StartupEvent ev, Scheduler scheduler) {
@RunOnVirtualThread
void run() {
VirtualThreadsAssertions.assertEverything();
// Quarkus specific - each VT has a unique name
executions.add(Thread.currentThread().getName());
// Quarkus specific - all VTs shares the same prefix
executions.add(Thread.currentThread().getName() + '-' + Thread.currentThread().getId());
}

@GET
Expand Down
Loading