• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to yield when connecting DB...

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic