Subject DataSource question
Author Juan Pedro López Sáez
Hello All,

This is a very simple question.

I'm using Jaybird 1.0.1, Tomcat and DBCP to implement a DataSource for
my database connections.

Till now I have a servlet Filter where I first initialize the DataSource
(in the Filter.init() method). For every request I get a database
Connection calling DataSource.getConnection() inside a synchonized block
(in the Filter.doFilter() method). When the request finishes, the Filter
closes the connection. So, every database connection is kept opened just
while the request is in process.

Now I want some requests to behave in a different fashion. I want them
to spawn a thread to make some long processing tasks in background. The
initial request will instead response to the client as soon as possible.
The matter is that I need to provide the new thread a database
connection which remains opened till the job is done.

My first solutions has been to pass the DataSource reference to the new
thread so that it can get its own database connection.

Question: is DataSource.getConnection() thread-safe? Is it java database
driver dependent? Are there any related to constraints?

I guess if it is really thread-safe I could probably remove the
synchonized block in my filter.

Thank you very much.

Juan Pedro Lopez