Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Synchronizing the connection object ?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic