aspose file tools*
The moose likes JDBC and the fly likes is a connection object thread safe ? what will happen if i use it in several thread ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "is a connection object thread safe ? what will happen if i use it in several thread ?" Watch "is a connection object thread safe ? what will happen if i use it in several thread ?" New topic
Author

is a connection object thread safe ? what will happen if i use it in several thread ?

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Hi
thank you for reading my post
what will happen if i use a connection object in several threads ?
and perform insert/delete oprtaion in that thread ?
will my data lost or currept ?
should i change the autocommit or transaction level stuff ?

thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
You should definitely not use a Connection object in more than one thread simultaneously. You're right that transaction issues would need to be considered, so unless you can guarantee that those aren't an issue, and are also sure that the threads won't access the Connection simultaneously, you shouldn't share it.


Ping & DNS - my free Android networking tools app
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Hi
Thank you for reply.
What about readonly use of a connection in several threadds?
if i just need to read some data from database in multiple threads
will it harm my application if i use a single connection in all those reader thread ?


thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
Read-only access may be OK, although it may not work if two threads issue commands at the same time. The behavior might be database-dependent, too (i.e., some drivers or databases may support this, while others may not).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is a connection object thread safe ? what will happen if i use it in several thread ?