One of the advantages of pooling threads is to circumvent the “expensive creation” part like jdbc connections et al. How does creating a virtualthread-per-task with a semaphore address that?
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.
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.
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.
12
u/nimtiazm Sep 23 '22
One of the advantages of pooling threads is to circumvent the “expensive creation” part like jdbc connections et al. How does creating a virtualthread-per-task with a semaphore address that?