• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A connection taken from Statement != used for creation it at pooling

 
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use Apache connection pool. Generally I close a connection after usage. Sometimes I can't reach an original connection, so I get it from a statement and close. I noticed that an original connection and one gotten from statement are not equal. Why it's so? Is any risk of connections leak when when I close connection from statement ?
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I noticed that an original connection and one gotten from statement are not equal.


If you're using Commons pooling,
the original one is a wrapped connection. The close() method is overridden to return the connection to the pool, in stead of closing the database connection.

When you're using the connection from the statement, it depends on the jdbc implementation. You might get the non-wrapped connection.

Closing it would not return the connection to the pool, and close the actual database connection.

You could test the scenario by creating a pool with one connection,
- Get connection from the pool,
- create a statement,
- get the connection from the statement
- close that connection.
- Get a connection from the pool.

If the last step fails, you have a leak.

Regards, Jan
 
D Rog
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I use Commons. I remember when I implemented a pool, I had a background process watching for closed wrapped connections and removed them from pool. I'm expecting a similar mechanism from Commons. Do you know if there any?
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.
You can provide a validation query.
Commons uses it to test the state of your connection before handing it over.
But there is (as far as I know) no mechanism to revoke wrapper connections that have not been returned to the pool.

Regards, Jan
 
D Rog
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so it shouldn't create a problem. If a pool forgets about given connection, then they will be picked up by GC.
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by D Rog:
Ok, so it shouldn't create a problem. If a pool forgets about given connection, then they will be picked up by GC.



You might run out of pool connections if you don't return them as expected, by closing the wrapping connection.

Regards, Jan
 
D Rog
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will happen if a pool keeps a track of given connections, if not, then it should not be a problem. Anyway, thank you for tips.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic