Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's impossible to make an asynchronous call <em>to the database</em> via JDBC, but you can make asynchronous calls <em>to JDBC</em> with <strong>Actors</strong> (e.g., actor makes calls to the DB via JDBC, and sends messages to the third parties, when the calls are over), or, if you like CPS, with <a href="http://en.wikipedia.org/wiki/Futures_and_promises#Promise%20pipelining" rel="noreferrer"><strong>pipelined futures (promises)</strong></a> (a good implementation is <a href="http://code.google.com/p/scalaz/" rel="noreferrer">Scalaz</a> <a href="http://docs.google.com/present/view?id=ddmk3f43_63zpg3jcgz" rel="noreferrer">Promises</a>)</p> <blockquote> <p>I don't consider that using a pool of threads is a solution because it doesn't scale, in the case of heavy concurrent requests this will spawn a very large number of threads.</p> </blockquote> <p>Scala actors by default are event-based (not thread-based) - continuation scheduling allows creating millions of actors on a standard JVM setup. </p> <p>If you're targeting Java, <a href="http://doc.akkasource.org/untyped-actors-java" rel="noreferrer">Akka Framework</a> is an Actor model implementation that has a good API both for Java and Scala.</p> <hr> <p>Aside from that, the synchronous nature of JDBC makes perfect sense to me. The cost of a database session is far higher than the cost of the Java thread being blocked (either in the fore- or background) and waiting for a response. If your queries run for so long that the capabilities of an executor service (or wrapping Actor/fork-join/promise concurrency frameworks) are not enough for you (and you're consuming too many threads) you should first of all think about your database load. Normally the response from a database comes back very fast, and an executor service backed with a fixed thread pool is a good enough solution. If you have too many long-running queries, you should consider upfront (pre-)processing - like nightly recalculation of the data or something like that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload