aspose file tools*
The moose likes JDBC and the fly likes Refresh() method of oracleConnectionCacheManager! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Refresh() method of oracleConnectionCacheManager!" Watch "Refresh() method of oracleConnectionCacheManager!" New topic
Author

Refresh() method of oracleConnectionCacheManager!

Wilson Tsing Yi
Greenhorn

Joined: Jul 12, 2004
Posts: 2
Dear Expert,

I feel painful when testing with the Refresh() method of oracleConnectionCacheManager. Pls help.

I am using oracle 10g JDBC Driver and conect to oracle 8.1.7 DB Server

I use 10g for detecting and replacing failed cached connection. But I have a big problem in my testing. PLs help. The number of connections (all are ESTABLISHED view at netstat) grows when calling
oracleDataSource's getConnection() method after calling to oracleConnectionCacheManager's refresh() method. Lastly, exception throws when it reached max. connection setting. In fact, the connection is oracle server is good and the cached connections are good also.

I expect that the refresh() method should find all connections are good and no connection replacement in my test. Incoming connection requests served from the original cached connections. However, My test found that every calling to refresh() will cause old connection or oracleDataSource can't be reused for next getConnection() equest. But old connections are still maintained in ESTABLISHED state. Hence, size of connection grows continuously if refresh() and getConnection() repeatedly. PLs help me , so that original cached connections can be used after tirggering refresh() method.

My Goal : my application can detect and replace the fail cached connections, so that my application can work normally without stopping and automatically reconect to DB , even DB server/network down and then resume.


(My Guess) Every time triggering to refresh() methods will created a new oracleDataSource object, from which new connection requests are served. However, the old connection in old oracleDataSource object still maintained. But can't be used.

***********************************************************
Pls correct me if any mistake made in my understanding .
Welcome suggestion. Further information. welcome let me know.
Thx!
***********************************************************


public class oraConnCacheManager {

static OracleConnectionCacheManager occm = null;
static java.util.Properties prop = new java.util.Properties ();
static OracleDataSource ods= null;
static String cacheName = "oraConnTest";

//oraMon is a thread for triggering refresh() repeatedly
static oraConnCacheMonitor oraMon=null;

public oraConnCacheManager()
throws dbException , SQLException
{
occm = OracleConnectionCacheManager.getConnectionCacheManagerInstance();

try
{
prop.setProperty("InitialLimit", "0");
prop.setProperty("MinLimit", "1" );
prop.setProperty("MaxLimit", "3");
prop.setProperty("MaxStatementsLimit", "10");
prop.setProperty("InactivityTimeout", "0");
prop.setProperty("AbandonedConnectionTimeout", "900");
prop.setProperty("PropertyCheckInterval", "60");
prop.setProperty("ValidateConnection", "true");
prop.setProperty("TimeToLiveTimeout", "0");
prop.setProperty("ConnectionWaitTimeout", "5");

} catch (Exception ex) {
System.out.println("Exception when creating Exception");
ex.printStackTrace();
}


try
{
ods = new OracleDataSource();
ods.setURL("jdbc racle:thin:@192.168.58.133:15111:locdb");
ods.setUser("codeCrackOpen");
ods.setPassword("codeCrackOpen");
ods.setLoginTimeout(0);
ods.setConnectionCachingEnabled(true);
ods.setConnectionCacheProperties(prop);
ods.setConnectionCacheName(cacheName);
occm.createCache(cacheName, ods, prop);

} catch (Exception odsExp) {
System.out.println("Exception when setting oracleDataSource");
odsExp.printStackTrace();
}

try
{
//repeatedly trigger following refreshInvalidConnectionInCache()
//10 sec interval
oraMon = new oraConnCacheMonitor();
oraMon.start();

} catch (Exception monExp) {
System.out.println("Exception when monExp");
monExp.printStackTrace();
}
} // end of oraConnCacheManager constructor


public static void refreshInvalidConnectionInCache()
throws Exception
{
occm.refreshCache(cacheName , OracleConnectionCacheManager.REFRESH_INVALID_CONNECTIONS);
occm.reinitializeCache(cacheName, prop);
}


public static void refreshAllConnectionInCache()
throws Exception
{
occm.refreshCache(cacheName , OracleConnectionCacheManager.REFRESH_ALL_CONNECTIONS);
occm.reinitializeCache(cacheName, prop);
}


public synchronized Connection getConnection()
throws dbException , SQLException
{
return ods.getConnection();
}


} // end of oraConnCacheManager

Best Regards & Thx!

Wilson
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

"Mr Wilson",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Refresh() method of oracleConnectionCacheManager!