Skip to content

Add virtual thread attribute to WsWebSocketContainer#936

Draft
adj5672 wants to merge 3 commits into
apache:mainfrom
adj5672:main
Draft

Add virtual thread attribute to WsWebSocketContainer#936
adj5672 wants to merge 3 commits into
apache:mainfrom
adj5672:main

Conversation

@adj5672

@adj5672 adj5672 commented Jan 6, 2026

Copy link
Copy Markdown

In my app, I use WsWebSocketContainer to create websocket client.
As the number of sessions increases, memory usage also increased. So "OOM Killed" occured frequently.
I know that It is a normal situation in thread-per-connection model which is current applied.
Current model have advantage that It is very intuitive and sometimes it behaves like kind of rate limiter.

But I think that threads for R/W may not working busy in some case.
Also platform thread will be created twice of session count and it allocate a lot of default stack memory.
furthermore context switching cost expensive too when using platform thread.

So I think that instead of create two platform thread per session, using virtual thread will be helpful in some cases.
Since I may not understand overall about websocket codes and architecture, I just create draft pull request.
Adding choice to use virtual threads would be helpful for optimizing memory usage.

@VolareYang

Copy link
Copy Markdown

Hi! I have a question: how do I enable virtual threads in Tomcat 11? After enabling virtual threads, which log in Tomcat's startup logs can I check to confirm that virtual threads are actually being used?

My environment:
Tomcat: 11.0.23
JDK: 21
server.xml configuration:

Startup logs show:
23-Jun-2026 14:51:39.306 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
23-Jun-2026 14:51:39.313 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [799] milliseconds

When I check the thread stack with the jstack command, I don't see any threads related to tomcat-virt- so I can't be sure if virtual threads are actually enabled. Could you guide me? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants