Hi, When the property "useVirtualThreads" is true, Tomcat create a VirtualThreadExecutor (https://github.com/apache/tomcat/blob/10.1.x/java/org/apache/tomcat/util/net/AbstractEndpoint.java#L1047) so a virtual thread is using (https://github.com/apache/tomcat/blob/10.1.x/java/org/apache/tomcat/util/threads/VirtualThreadExecutor.java#L38) to execute org.apache.tomcat.util.net.Nio2Endpoint$Nio2Acceptor
but you are right that the AsynchronousServerSocketChannel in Nio2Endpoint is not using a VirtualThreadExecutor (https://github.com/apache/tomcat/blob/10.1.x/java/org/apache/tomcat/util/net/Nio2Endpoint.java#L120) because it is not an ExecutorService but an Executor, so AsynchronousServerSocketChannel is using a ThreadPoolExecutor. A code like this is executing AsynchronousServerSocketChannel with Virtual Threads (fast code, so probably bad) : if (getExecutor() == null) { createExecutor(); } if (getExecutor() instanceof ExecutorService) { threadGroup = AsynchronousChannelGroup.withThreadPool((ExecutorService) getExecutor()); } else if (getExecutor() instanceof VirtualThreadExecutor) { threadGroup = AsynchronousChannelGroup.withThreadPool(Executors.newVirtualThreadPerTaskExecutor()); } What do you think about this ? It is a bug or a choice of tomcat teams that only Nio2Acceptor are on virtual thread and not AsynchronousServerSocketChannel? To test this, I duplicate the TestMaxConnections test and add Assert.assertTrue(tomcat.getConnector().setProperty("useVirtualThreads", "true")); Regards, Nicolas > Le 8 déc. 2023 à 03:49, Han Li <li...@apache.org> a écrit :x > > Hi Nicolas, > > I took a quick look that Tomcat's VirtualThreadExecutor does not implement > the ExecutorService interface, which leads to this result. > > So I think this is a Tomcat bug. > > Han > >> On Dec 8, 2023, at 03:55, Nicolas BONAMY <nicolas.bona...@gmail.com> wrote: >> >> Hi, >> >> I try to use virtual thread on Apache Tomcat 10.1.16 with this configuration >> on macOS or on Linux: >> >> <Executor name="tomcatThreadPoolVirtual" >> class="org.apache.catalina.core.StandardVirtualThreadExecutor"/> >> >> <Connector port="8080" >> protocol="org.apache.coyote.http11.Http11Nio2Protocol" >> connectionTimeout="20000" >> redirectPort="8443" >> maxParameterCount="1000" >> useVirtualThreads="true" >> /> >> But when I make a request, I'm not on a virtual thread : >> Thread[#76,Thread-14,5,main] . I profiled my application too but no virtual >> threads are used. >> >> If I use a Http11NioProtocol instead of Http11Nio2Protocol, all requests are >> on virtual thread : >> VirtualThread[#65,http-nio-8080-virt-0]/runnable@ForkJoinPool-1-worker-1 >> >> <Executor name="tomcatThreadPoolVirtual" >> class="org.apache.catalina.core.StandardVirtualThreadExecutor"/> >> >> >> <Connector port="8080" >> protocol="org.apache.coyote.http11.Http11NioProtocol" >> connectionTimeout="20000" >> redirectPort="8443" >> maxParameterCount="1000" >> useVirtualThreads="true" >> /> >> Http11Nio2Protocol is not working with virtual threads? Has anyone >> encountered this problem before? > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org >