• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

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???


0
aimueller
Asked:
aimueller
  • 2
1 Solution
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now