• 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

Query regarditng Connection Pooling

 
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If i didn't close the Connection (didn't perform con.close or con==null)

After the request completes :

will this Connection instance will return back to the Connection pool or will this result in a Memory Leak ?

( I am using DataSource support from Weblogic)

 
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
If you do not close your connection, this will result in connection leak.

conn == null will not result in closing a connection. You merely check if variable conn h is null or not.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jann , Thanks for the reply .

what i was expecting is that DBCP from Apache has the ability to close the connection for useven if we didn't close .

Did other containers like weblogic provided this facilty ?
 
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 have to return the connection to the pool, by calling it's close(). Also for other ConnectionPool implementations.
The mechanism is:

You ask a connection from the pool.
You use the connection to perform one or more sql activities
You return the connection to the pool by closing the connection.

Regards, Jan
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

RaviNada Kiran wrote:what i was expecting is that DBCP from Apache has the ability to close the connection for useven if we didn't close .


Most datasource providers will close the connection eventually if you don't. Relying on this still causes a connection leak because it doesn't happen right away.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Relying on this still causes a connection leak because it doesn't happen right away



Can you please tell what do you mean by "it doesn't happen right away"

Thanks in advance .
 
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

RaviNada Kiran wrote:Can you please tell what do you mean by "it doesn't happen right away"Thanks in advance .

It doesn't happen when you are finished with the connection. It *might* happen when the pool decides to do so.

The hint that we are all trying to give you is: don't rely on it. Close your connections properly.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good point Jan .

can you please tell me what are the conditions on which the the container decides to return the Connection instance to the pool .

Thanks in advance.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

RaviNada Kiran wrote:can you please tell me what are the conditions on which the the container decides to return the Connection instance to the pool .


They aren't specified and might not be deterministic. I'm having trouble picturing why you need to know this. If you always close your connections, this is never a problem.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:

RaviNada Kiran wrote:can you please tell me what are the conditions on which the the container decides to return the Connection instance to the pool .


They aren't specified and might not be deterministic. I'm having trouble picturing why you need to know this. If you always close your connections, this is never a problem.


yes, anyway connection pool program have a mechanism to get the connection when timeout or unuseful connection check triggered.
but close it explicitly is good custom.

Actually, i have met the issue, my environment is oralce9i+jdk1.4+ojdbc14.jar
i don't know why get a connection from pool is slow to me, and the connection haven't back to pool although i closed.
Thanks for your any suggestion .

**
* java file1 named ServerInformationInit, initinal connection pool cache. Any update need?
*
*/
public static OracleDataSource ods = new OracleDataSource(); // is a statci variable will be used in other java file
prop.setProperty("MinLimit", "5");// set cache properties
prop.setProperty("MaxLimit", "20");
prop.setProperty("InitialLimit", "5");
prop.setProperty("ConnectionWaitTimeout","3");
prop.setProperty("InactivityTimeout", "3");
ods.setConnectionCachingEnabled(true); // be sure set to true
ods.setConnectionCacheProperties(prop);
ods.setConnectionCacheName("eform_db_cache"); // this cache's name
url = "jdbcracle:thin:@" + EformAplProperty.getDbHostName() + ":" +
EformAplProperty.getDbPort() + ":" + EformAplProperty.getDbSid();
ods.setURL(url);
ods.setUser(EformAplProperty.getDbUserName());
ods.setPassword(EformAplProperty.getDbPassword());


/**
* java file 2 named DefnSqlManager is all DAO file's parent
*/
connection = ServerInformationInit.ods.getConnection();
...............
OracleConnectionCacheManager occm =
OracleConnectionCacheManager.getConnectionCacheManagerInstance();
System.out.println
(occm.getNumberOfAvailableConnections("eform_db_cache")
+ " connections are available in cache " + "eform_db_cache");
System.out.println
(occm.getNumberOfActiveConnections("eform_db_cache")
+ " connections are active");

/**
* java file 3 named QaCmptCaseSqlManager extend DefnSqlManager, which retrieve data from database
*/
sqlMgr = new QaCmptCaseSqlManager();
cmptEntity = sqlMgr.genCmptCaseDoc(docId)
finally {
sqlMgr.closeDbConn();
}

below message is printed in console:
4 connections are available in cache eform_db_cache
14 connections are active
3 connections are available in cache eform_db_cache
15 connections are active
4 connections are available in cache eform_db_cache
14 connections are active
3 connections are available in cache eform_db_cache
15 connections are active
2 connections are available in cache eform_db_cache
2 connections are available in cache eform_db_cache
16 connections are active
16 connections are active

As you see, the connections are available in cache is less and most of connections are in active.
The result is system will create more and more connection for application, i don't what wrong about it ?

Filename toad_sessiones.JPG Download
Description the sessiones in toad are equal to java connectiones?
Filesize 55 Kbytes
Downloaded: 1 time(s)

the original url is https://coderanch.com/t/440913/Oracle-OAS/ojdbc-jar-connection-pool-cache
 
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
It's better to create a new topic when you want to discuss a problem not related to the OP subject. (ah - you did that already)
 
ken zhu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Cumps wrote:It's better to create a new topic when you want to discuss a problem not related to the OP subject. (ah - you did that already)


Yes, i did. But nobody reply me and i found this topic is similar with it so.....
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic