Skip to content

The default virtual thread executor should created named threads #11353

@danishnawab

Description

@danishnawab

Jetty version(s)
12.0.5

Enhancement Description

Specify a ThreadFactory when setting up the default virtual thread executor so it creates named threads.

Background

The virtual threads created by Jetty's VirtualThreads#getDefaultVirtualThreadsExecutor do not have a thread name.

Unlike platform threads, virtual threads do not return a name unless explicitly set. From the javadoc:

Virtual threads do not have a thread name by default. The getName method returns the empty string if a thread name is not set.

And jetty does not specify a ThreadFactory when creating the Executor internally: link.

The combination of the above two things leads to a reduced troubleshooting experience because things like logs and thread dumps do not contain a useful thread name anymore.

Of course, the consumers could set their own virtual thread executors in VirtualThreads.Configurable#setVirtualThreadsExecutor but that's not what Spring Boot does as it just uses the default executor offered by Jetty: link.

Proposal
Given that Jetty does offer a default executor, it would be good to configure it so it creates named threads.

Now on to the question of what might be a good name in this case: since we don't know the use cases of the consumers, it would be good to give it a generic prefix e.g. jetty-vt-N (where N is the ID incremented internally by the ThreadFactory for each thread it creates).

I don't think it is necessary to allow making this prefix configurable as the consumers could always provide a custom virtual thread executor. (Potentially relevant discussion in #8863)
But with a default (and non-configurable) prefix, we will at least have a sane default in place.

Here's a draft of what such a change might look like: jetty-12.0.x...danishnawab:jetty.project:jetty#11353#diff-0d363273d70f3e11ace94a7a6df43bd1b8d50ffe0629aee6cc3f31805084c047

If these changes are acceptable, I can open a PR for you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions