• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to yield when connecting DB...

 
Tom Wang
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you think this blocks other threads?
You could open the task-manager on win, or call 'top' on linux, and look.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!