• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

About Connection.close()

 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!!

I am getting Connection from the using DataSouce by following code...



I am using following code to close the Connection

I want to know here, by doing Connection.close(), does the Connection object returns to the ConnectionPool?

Reg,
Chetan
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, and close the connection in your finally block.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah closing in finally block only.

But suppose if I have 10 open connetions, and I close a connection using above mentioned code, then I will have 10-1 = 9 open connections, right?
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me rephrase my post. You should close your connection the moment that you do not need it and also close it in your finally block. This will keep the number of open connections to a minimum.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chetan Parekh:
Yeah closing in finally block only.

But suppose if I have 10 open connetions, and I close a connection using above mentioned code, then I will have 10-1 = 9 open connections, right?



No. If you are getting connections from a connection pool set up in weblogic using that datasource, when you close the connection it is returned to the pool. It would then be available for the next request that asks for a connection.

You can monitor connections in the console, see Monitoring Connections in a JDBC Connection Pool.

If a new connection is opened for each new user or request, you have probabaly missed a place where the connection isn't getting closed.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also configure WebLogic Server to pin a connection to a particular thread. Closing the connection will in such a case cause WebLogic Server to reserve the connection to the thread, so the connection will not be returned to the pool. When the same thread needs a connection again, WebLogic Server will provide the reserved connection. If the thread needs additional connections, then WebLogic Server will create additional connections and pin them to the thread.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic