I am updating a Kotlin (v1.9.25) Spring Boot (v3.3.1) project from Java 17 to Java 21 in order to enable Virtual Threads.
In our service, almost all requests acquire one database connection and hold to it for the whole request, while some very specific ones require more than one. To avoid database connection starvation, we set the maximum number of database connections to be just a little above the maximum concurrent requests.
spring.threads.virtual.enabled: true
spring.datasource.hikari.maximum-pool-size: 50
server.tomcat.threads.max: 4 # used to be 45 before virtual threads
Up to now, we control maximum concurrent requests by means of server.tomcat.threads.max
, but with virtual threads it all changes: the idea, as far as I understand, is to have a executor receiving an unlimited amount of tasks, so no limits here.
That leaves me to my question: how can I limit the maximum number of concurrent connections on my service while using virtual threads?
I thought of implementing a semaphore but something seems to be off with this approach, I though that it would be configurable.
Thank you very much!