java - Getting Stale Connection using OracleDataSource with OCI driver -


i getting stale connection error when there no requests database java application couple of hours.

its simple java application runned on linux box oci (type driver). dont ask me why oci, why not thin. using oracledatasource , oracleconnectioncachemanager maintaining cache of connection objects. here code snippet:

import java.sql.connection;  import java.sql.sqlexception;  import java.util.properties;   import oracle.jdbc.pool.oracleconnectioncachemanager;  import oracle.jdbc.pool.oracledatasource;   import org.apache.log4j.logger;   import com.exception.dataexception;   public class connectionmanager {  private static oracledatasource pooldatasource = null;  private final static string cache_name = "connection_pool_cache";  private static oracleconnectioncachemanager occm = null;   public static void init(string url,string userid,string password) throws pctdataexception{  properties cacheprops = null;  try {  pooldatasource = new oracledatasource();  pooldatasource.seturl(url);  pooldatasource.setuser(userid);  pooldatasource.setpassword(password);   cacheprops = new properties();  cacheprops.setproperty("minlimit", "1");  cacheprops.setproperty("maxlimit", "5");  cacheprops.setproperty("initiallimit", "1");  cacheprops.setproperty("validateconnection", "true");   pooldatasource.setconnectioncachingenabled(true);  occm = oracleconnectioncachemanager.getconnectioncachemanagerinstance();  occm.createcache(cache_name, pooldatasource, cacheprops);  occm.enablecache(cache_name);  } catch (sqlexception se) {  throw new dataexception("sql exception while initializing connection pool");  }catch(exception e){  throw new dataexception("exception while initializing connection pool");  }  }   public static connection getconnection() throws pctdataexception {  try{  if (pooldatasource == null) {  throw new sqlexception("oracledatasource null.");  }  occm.refreshcache(cache_name, oracleconnectioncachemanager.refresh_invalid_connections);  connection connection = pooldatasource.getconnection();  return connection;  }catch(sqlexception se){  se.printstacktrace();  throw new dataexception("exception while getting connection object");  }catch(exception e){  e.printstacktrace();  throw new dataexception("exception while getting connection object");  }  }   public static void closepooledconnections() {  try{  if (pooldatasource != null) {  pooldatasource.close();  }  }catch(sqlexception se){  }catch(exception e){  }   }  }  

the error follows:

connectionmanager.java:getconnection:87 - exception while getting connection object:  java.sql.sqlexception: invalid or stale connection found in connection cache  @ oracle.jdbc.driver.databaseerror.throwsqlexception(databaseerror.java:112)  @ oracle.jdbc.driver.databaseerror.throwsqlexception(databaseerror.java:146)  @ oracle.jdbc.driver.databaseerror.throwsqlexception(databaseerror.java:208)  @ oracle.jdbc.pool.oracleimplicitconnectioncache.getconnection(oracleimplicitconnectioncache.java:390)  @ oracle.jdbc.pool.oracledatasource.getconnection(oracledatasource.java:404)  @ oracle.jdbc.pool.oracledatasource.getconnection(oracledatasource.java:189)  

what missing?

maybe need set keep alives on? periodically, when not in use send ping database server saying still here , don't close me out. not fun try debug though. problem setting on database server there max connection age, or time kill idle connections. there settings in pool use check , tell new 1 when happens. wish more have not worked oracle.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -