aspose file tools*
The moose likes JDBC and the fly likes Synchronizing the connection object ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Synchronizing the connection object ?" Watch "Synchronizing the connection object ?" New topic
Author

Synchronizing the connection object ?

Vetrik Kumaran
Greenhorn

Joined: Jul 01, 2003
Posts: 7
Can I synchronize the connection object?

If I do what are the advantage and disadvantages?

Or the connection object should never be synchronized.........

If yes, is there a good approach to implement the same....



Try Try Try...
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
The only reason to sycnhronize a connection object would be if you were sharing it among multiple threads. Sharing a single connection among multiple threads is a very very very very bad idea.

So no, don't allow more than one thread to use an open connection and then you don't have to synchronize.

If you decide to ignore this advice and allow multiple threads to use a connection object, then only only thread at a time can use the object while it is open, which of course you could accomplish with synchronization. This will make your programmer between 100 and 1,000,000 times slower for some operations though (if it's multi-threaded). Like I said, a very bad idea.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Synchronizing the connection object ?