When using an API such as JDBC, their function calls are Blocking, not suspending, such as Statement::executeQuery or Satement::executeUpdate.
This means that for any kind of operation you have to block a Thread. If you are waiting for 10k of queries to complete, you should have 10k of threads in your JVM.
We can reduce the amount of created Threads with pools, but they can not reduce the amount of waiting Threads.
This raises many issues:
- Coroutines ARE NOT light-weight -> In this case, they require a whole thread!
- Thread-Safety issues -> This approach forces you to use several threads concurrently, they may be usually sleeping but a bunch of them can wake up at the same time and modify shared state.
What are the best practices when dealing with this APIs?