Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clone DBConnection Object

 
Shankar sanjay
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


I understand that Deep copy (clone) will return new separate object. So I am thinking like this..

i will create a DB connection object(say dbConnection) while my application start up, and stored it in cache. After that, whenever data base connection require then i will get a clone of dbConnection and try to process further.

can you please advice, this will be a good approach?

 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This (most probably) is not going to work. Not all objects are cloneable. A database connection has to be established by calling the database server and it keeps some communication channel to the database open, these things from their very nature are not cloneable.

That said, a database connection might implement the Clonable interface and make sure to actually open a new connection when cloned, however I'd say no JDBC driver does so. It does not make much sense. A Connection Pool is usually used to re-use connection resources.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic