Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Question about Database Connection Pools

Thread view: 
apue - 23 Jul 2006 17:41 GMT
Hi Newsgroup,

i have written an Objectpool for Database connections. All locked
connections are stored within a Vector (called _used) and all unlocked
connections are stored within a second Vector (called _unused).

Now consider the following situation:

------------------- code ---------------------------------------
DbConnectionPool pool = new DbConnectionPool( driver, url, user, passwd);
Connection dbcon = pool.getConnection();

int sizeUsed = pool.getUsed(); // returns 1, thats ok

// ...
// ... lets do some actions with dbcon ....
// ...
// ... programmer does not notice
// ... that dbcon is still in use.
// ... so he checks out a new connection
//
dbcon = pool.getConnection();

sizeUsed = pool.getUsed(); //  return 2, uppps!!!

------------------- code ---------------------------------------

Because the programmer checks out a new connections, two database
connections are now marked as _used.

Is there any possibility to avoid such situations?

Thank you in advance

mike
Dorian - 23 Jul 2006 21:56 GMT
Well it's possible that the behavior you currently have would meet the
expectations of someone using your pool but if you want to enforce the
same connection being returned you could store it in a ThreadLocal
variable when getConnection() is called.  This would require that the
connection returned is subclassed to override the close() method which
would remove it from the ThreadLocal and add it back to the pool.

With all the freely available connection pools why are you writing your own?

Regards,
Bob

> Hi Newsgroup,
>
[quoted text clipped - 27 lines]
>
> mike


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.