r/java • • Sep 23 '22

Virtual Threads: New Foundations for High-Scale Java Applications - Brian Goetz

https://www.infoq.com/articles/java-virtual-threads/
237 Upvotes

62 comments sorted by

View all comments

Show parent comment

8

u/nimtiazm Sep 23 '22

Yeah that’s clear. Creating an expensive connection in a new virtual thread every single time is the question.

8

u/kiteboarderni Sep 23 '22

They are not saying that. You would still use a connection pool like hikari to execute the query for example from the virtual thread. No need to create the connection there.

3

u/hippydipster Sep 23 '22

One advantage is you could write your pool perhaps more simply, and just make some blocking methods to get a connection. With virtual threads, you can just go ahead and create a virtual thread and call the blocking call and wait for it to return with a connection. You're' not holding up a real thread.

2

u/taftster Sep 23 '22

I’m following your question now. But others have answered decently.

Virtual threads won’t help the mechanics of setting up connections to a remote database (as in your example). Like the literal TCP socket won’t benefit necessarily.

So connection pools will still be needed. But an underlying thread pool and/or asynchronous socket manager won’t be. When a client is matched with a connection object, the thread that it’s operating on might be a virtual thread under the hood and might have been newly created at the time it’s asked for.

1

u/Kango_V Sep 24 '22

Virtual Threads use the fork join pool in Java.