Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Question about Database Connection Pools

Reply
Thread Tools

Question about Database Connection Pools

 
 
apue
Guest
Posts: n/a
 
      07-23-2006
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

 
Reply With Quote
 
 
 
 
Dorian
Guest
Posts: n/a
 
      07-23-2006
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

On 2006-07-23 11:41:23 -0500, apue <> said:

> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
connection pools for database and web sessions marvind Java 0 02-01-2006 06:28 PM
Tomcat 4.0, MySQL and connection pools... Darryl L. Pierce Java 0 08-18-2003 08:15 PM
Maybe Database connection pools should be managed by Admins instead of Developers using Code? Eric Newton ASP .Net Security 0 08-15-2003 07:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57