Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@RunOnVirtualThread Not Working with Undertow Servlet #42274

Closed
otavioprado opened this issue Aug 1, 2024 · 5 comments
Closed

@RunOnVirtualThread Not Working with Undertow Servlet #42274

otavioprado opened this issue Aug 1, 2024 · 5 comments
Labels
area/virtual-threads Issue related to Java's Virtual Threads kind/enhancement New feature or request

Comments

@otavioprado
Copy link

otavioprado commented Aug 1, 2024

Describe the bug

The @RunOnVirtualThread annotation seems not to work as expected when used in the Undertow extension. Specifically, the servlet's service method does not run on a virtual thread as intended.

Code:

@WebServlet(urlPatterns = "/*")
@RunOnVirtualThread
public class MyServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException {
        Log.infof( "Current thread: %s", Thread.currentThread().getName());
        Log.infof("Is virtual thread? %s", Thread.currentThread().isVirtual());
    }
}

Log:

2024-08-01 14:55:41,415 INFO  [com.sen.api.ser.MyServlet] (executor-thread-1) Current thread: executor-thread-1
2024-08-01 14:55:41,416 INFO  [com.sen.api.ser.MyServlet] (executor-thread-1) Is virtual thread? false

Expected behavior

The service method should run on a virtual thread, and the logs should indicate that the current thread is a virtual thread.

Actual behavior

The service method does not appear to run on a virtual thread as expected. Instead, it runs on a regular thread.

How to Reproduce?

  1. Set up a Quarkus project using the Undertow extension.
  2. Create a new Java class named MyServlet that extends HttpServlet. Annotate the class's service method with @RunOnVirtualThread.
  3. In the service method, add logging statements to output the current thread's name and whether it is a virtual thread.
  4. Send an HTTP request to the servlet endpoint to trigger the service method.
  5. Check the application logs for the output from the logging statements. Observe the thread name and whether it is marked as a virtual thread.

Output of uname -a or ver

Linux latitude 6.5.0-45-generic #45~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Jul 15 16:40:02 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "21.0.1" 2023-10-17 LTS

Quarkus version or git rev

3.13.0

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.7

Additional information

No response

@otavioprado otavioprado added the kind/bug Something isn't working label Aug 1, 2024
Copy link

quarkus-bot bot commented Aug 1, 2024

/cc @cescoffier (virtual-threads), @ozangunalp (virtual-threads)

@quarkus-bot quarkus-bot bot added the area/virtual-threads Issue related to Java's Virtual Threads label Aug 1, 2024
@mkouba
Copy link
Contributor

mkouba commented Aug 7, 2024

AFAIK the quarkus-undertow extension does not support virtual threads, and @RunOnVirtualThread in general. The virtual threads reference guide mentions quarkus-rest, quarkus-messaging, quarkus-grpc and quarkus-scheduler.

Moreover, quarkus-websockets-next, quarkus-reactive-routes and quarkus-vertx do support virtual threads as well.

The rule is as follows - if the docs explicitly do not mention the support for @RunOnVirtualThread then it's very likely not supported ;-).

@mkouba mkouba added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Aug 7, 2024
@otavioprado
Copy link
Author

@mkouba
Do you know if there are plans to add support for virtual threads in quarkus-undertow when Jakarta EE 11 is released? It would be great to know if this is on the roadmap.

Thank you!

@mkouba
Copy link
Contributor

mkouba commented Aug 7, 2024

I don't know if there's a plan to add VT support to quarkus-undertow but given the fact that Servlet API is not the preferred programming model for webapps in Quarkus (compared to quarkus-rest, quarkus-grpc, etc.) I don't think it would be a high priority.

@cescoffier
Copy link
Member

There is no plan to support virtual threads with undertow (servlets).

@cescoffier cescoffier closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/virtual-threads Issue related to Java's Virtual Threads kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants