sharing jdbc connection between java threads

P

patrick boulay

I am wondering how to share jdbc connection between java threads
anyone with experience with this , code etc .
thank you
patrick
 
D

Daniel Pitts

patrick said:
I am wondering how to share jdbc connection between java threads
anyone with experience with this , code etc .
thank you
patrick
a JDBC connection is not guaranteed to be thread safe. You have to make
sure that all access to it is serialized. It is probably better to have
a connection-per-thread, or offload db work into a separate worker
thread, perhaps using a queue similar to the AWT EventQueue.
 
A

Arne Vajhøj

patrick said:
I am wondering how to share jdbc connection between java threads
anyone with experience with this , code etc .

You don't.

One connection per thread using the database.

Arne
 
A

Arne Vajhøj

Daniel said:
a JDBC connection is not guaranteed to be thread safe.

It is almost guaranteed to not be thread safe.

For most databases a connection is really a socket connection
to the database where query results is being streamed back.

Without some multiplexing logic in the driver having multiple
query results streamed out mixed would not work.

[newer SQLServer actually has such logic]

Arne
 
Joined
Apr 2, 2009
Messages
1
Reaction score
0
You can also set a property in DB2 on how the connections are shared:

Determines whether connections are shared based on the current state of the connection (-1) or the original connection request (0).

To specify with greater granularity which connection
properties are matched based on the current state, you may combine the following constants by
adding them together: 1=transaction isolation level, 2=read only, 4=holdability, 8=type map, 16=catalog.

However, I would be careful using anything else than transaction isolation level.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top