Hello. How a thread yields the CPU time to the other thread when it's spending time to connect DataBase (e.g. DriverManager.getConnection(...)) or waiting for a big SQL return ? (e.g. stmt.executeQuery("select * from....")) thanks.
The JVM is pretty much allowed to pause execution of one thread between any two bytecode instructions and go execute another thread for a while. So if you have a thread that sits on one instruction - say waiting for the database to respond to a connect or select - the JVM is likely to get bored waiting and go run another thread. That's overly simplistic - the actual rules of when it can interrupt one thread and run another are tricky. The Java Language Spec lays it all out in gory detail if that sounds fun.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi