Design consideration for multithreaded jdbc application using connection pooling

Hi,
my application involves connecting to Oracle using connection pooling (with tomcat).

How to make sure that the db connection is thread safe???

Specially on working with blobs???


aimuellerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kiranhkCommented:
basically you need to have a synchronized method while getting the connection from the pool
like
public Connection getConnection()
{
synchronized(Datasource)
{
datasource.getConnection()
return connection
}
}

this way it will be thread safe and each of your threads will be getting individual connections.
0
aimuellerAuthor Commented:
How to make sure that the db connection (Oracle) while reading a blob is thread safe???
0
TimYatesCommented:
Errr....

you don't share connections between threads...  That would be a very bad thing...

So you will basiacally be relying on the skills of the people who write your connection pool, and the JDBC driver itself...
0
kiranhkCommented:
as i said before when u get the connection from the datasource your threads should each have their own connections... so dont make the connection variable as a common  variable which can be accessible to all the threads..... meaning dont make it static/final etc ettc...

whenever you create a thread of a particular thread it should get its own connection object...
so declare a connection variable in your class making it extend the Thread/implement Runnable..... inside the run method call the get Connection method to retrieve the connection from the DataSource and assign it to the connection variable.....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.