/** * Flag to remove abandoned connections if they exceed the * removeAbandonedTimout. * * Set to true or false, default false. * If set to true a connection is considered abandoned and eligible * for removal if it has been idle longer than the removeAbandonedTimeout. * Setting this to true can recover db connections from poorly written * applications which fail to close a connection. * @deprecated */ public boolean getRemoveAbandoned() { if (abandonedConfig != null) { return abandonedConfig.getRemoveAbandoned(); } return false; }
/** * Create an ObjectPool which tracks db connections. * * @param factory PoolableObjectFactory used to create this * @param config configuration for abandoned db connections */ public AbandonedObjectPool(PoolableObjectFactory factory, AbandonedConfig config) { super(factory); this.config = config; System.out.println("AbandonedObjectPool is used (" + this + ")"); System.out.println(" LogAbandoned: " + config.getLogAbandoned()); System.out.println(" RemoveAbandoned: " + config.getRemoveAbandoned()); System.out.println(" RemoveAbandonedTimeout: " + config.getRemoveAbandonedTimeout()); }
/** * Flag to remove abandoned connections if they exceed the * removeAbandonedTimout. * * Set to true or false, default false. * If set to true a connection is considered abandoned and eligible * for removal if it has been idle longer than the removeAbandonedTimeout. * Setting this to true can recover db connections from poorly written * applications which fail to close a connection. * <p> * Abandonded connections are identified and removed when * {@link #getConnection()} is invoked and the following conditions hold * <ul><li>{@link #getRemoveAbandoned()} = true </li> * <li>{@link #getNumActive()} > {@link #getMaxActive()} - 3 </li> * <li>{@link #getNumIdle()} < 2 </li></ul></p> */ public boolean getRemoveAbandoned() { if (abandonedConfig != null) { return abandonedConfig.getRemoveAbandoned(); } return false; }
/** * Flag to remove abandoned connections if they exceed the * removeAbandonedTimout. * * Set to true or false, default false. * If set to true a connection is considered abandoned and eligible * for removal if it has been idle longer than the removeAbandonedTimeout. * Setting this to true can recover db connections from poorly written * applications which fail to close a connection. * <p> * Abandonded connections are identified and removed when * {@link #getConnection()} is invoked and the following conditions hold * <ul><li>{@link #getRemoveAbandoned()} = true </li> * <li>{@link #getNumActive()} > {@link #getMaxActive()} - 3 </li> * <li>{@link #getNumIdle()} < 2 </li></ul></p> */ public boolean getRemoveAbandoned() { if (abandonedConfig != null) { return abandonedConfig.getRemoveAbandoned(); } return false; }
/** * Return a db connection to the pool. * * @param obj db Connection to return * @throws Exception if an exception occurs returning the connection * to the pool */ public void returnObject(Object obj) throws Exception { if (config != null && config.getRemoveAbandoned()) { synchronized (trace) { boolean foundObject = trace.remove(obj); if (!foundObject) { return; // This connection has already been invalidated. Stop now. } } } super.returnObject(obj); }
/** * Invalidates an object from the pool. * * @param obj object to be returned * @throws Exception if an exception occurs invalidating the object */ public void invalidateObject(Object obj) throws Exception { if (config != null && config.getRemoveAbandoned()) { synchronized (trace) { boolean foundObject = trace.remove(obj); if (!foundObject) { return; // This connection has already been invalidated. Stop now. } } } super.invalidateObject(obj); }
/** * Invalidates an object from the pool. * * @param obj object to be returned * @throws Exception if an exception occurs invalidating the object */ public void invalidateObject(Object obj) throws Exception { if (config != null && config.getRemoveAbandoned()) { synchronized (trace) { boolean foundObject = trace.remove(obj); if (!foundObject) { return; // This connection has already been invalidated. Stop now. } } } super.invalidateObject(obj); }
/** * Return a db connection to the pool. * * @param obj db Connection to return * @throws Exception if an exception occurs returning the connection * to the pool */ public void returnObject(Object obj) throws Exception { if (config != null && config.getRemoveAbandoned()) { synchronized (trace) { boolean foundObject = trace.remove(obj); if (!foundObject) { return; // This connection has already been invalidated. Stop now. } } } super.returnObject(obj); }
/** * Invalidates an object from the pool. * * @param obj object to be returned * @throws Exception if an exception occurs invalidating the object */ public void invalidateObject(Object obj) throws Exception { if (config != null && config.getRemoveAbandoned()) { synchronized (trace) { boolean foundObject = trace.remove(obj); if (!foundObject) { return; // This connection has already been invalidated. Stop now. } } } super.invalidateObject(obj); }
/** * Return a db connection to the pool. * * @param obj db Connection to return * @throws Exception if an exception occurs returning the connection * to the pool */ public void returnObject(Object obj) throws Exception { if (config != null && config.getRemoveAbandoned()) { synchronized (trace) { boolean foundObject = trace.remove(obj); if (!foundObject) { return; // This connection has already been invalidated. Stop now. } } } super.returnObject(obj); }
/** * Get a db connection from the pool. * * If removeAbandoned=true, recovers db connections which * have been idle > removeAbandonedTimeout and * getNumActive() > getMaxActive() - 3 and * getNumIdle() < 2 * * @return Object jdbc Connection * @throws Exception if an exception occurs retrieving a * connection from the pool */ public Object borrowObject() throws Exception { if (config != null && config.getRemoveAbandoned() && (getNumIdle() < 2) && (getNumActive() > getMaxActive() - 3) ) { removeAbandoned(); } Object obj = super.borrowObject(); if (obj instanceof AbandonedTrace) { ((AbandonedTrace) obj).setStackTrace(); } if (obj != null && config != null && config.getRemoveAbandoned()) { synchronized (trace) { trace.add(obj); } } return obj; }
/** * Get a db connection from the pool. * * If removeAbandoned=true, recovers db connections which * have been idle > removeAbandonedTimeout and * getNumActive() > getMaxActive() - 3 and * getNumIdle() < 2 * * @return Object jdbc Connection * @throws Exception if an exception occurs retrieving a * connection from the pool */ public Object borrowObject() throws Exception { if (config != null && config.getRemoveAbandoned() && (getNumIdle() < 2) && (getNumActive() > getMaxActive() - 3) ) { removeAbandoned(); } Object obj = super.borrowObject(); if (obj instanceof AbandonedTrace) { ((AbandonedTrace) obj).setStackTrace(); } if (obj != null && config != null && config.getRemoveAbandoned()) { synchronized (trace) { trace.add(obj); } } return obj; }
/** * Get a db connection from the pool. * * If removeAbandoned=true, recovers db connections which * have been idle > removeAbandonedTimeout and * getNumActive() > getMaxActive() - 3 and * getNumIdle() < 2 * * @return Object jdbc Connection * @throws Exception if an exception occurs retrieving a * connection from the pool */ public Object borrowObject() throws Exception { if (config != null && config.getRemoveAbandoned() && (getNumIdle() < 2) && (getNumActive() > getMaxActive() - 3) ) { removeAbandoned(); } Object obj = super.borrowObject(); if (obj instanceof AbandonedTrace) { ((AbandonedTrace) obj).setStackTrace(); } if (obj != null && config != null && config.getRemoveAbandoned()) { synchronized (trace) { trace.add(obj); } } return obj; }
if ((abandonedConfig != null) && (abandonedConfig.getRemoveAbandoned())) { connectionPool = new AbandonedObjectPool(null,abandonedConfig);
/** * Creates a connection pool for this datasource. This method only exists * so subclasses can replace the implementation class. */ protected void createConnectionPool() { // Create an object pool to contain our active connections GenericObjectPool gop; if ((abandonedConfig != null) && (abandonedConfig.getRemoveAbandoned())) { gop = new AbandonedObjectPool(null,abandonedConfig); } else { gop = new GenericObjectPool(); } gop.setMaxActive(maxActive); gop.setMaxIdle(maxIdle); gop.setMinIdle(minIdle); gop.setMaxWait(maxWait); gop.setTestOnBorrow(testOnBorrow); gop.setTestOnReturn(testOnReturn); gop.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun); gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); gop.setTestWhileIdle(testWhileIdle); connectionPool = gop; }
/** * Creates a connection pool for this datasource. This method only exists * so subclasses can replace the implementation class. */ protected void createConnectionPool() { // Create an object pool to contain our active connections GenericObjectPool gop; if ((abandonedConfig != null) && (abandonedConfig.getRemoveAbandoned())) { gop = new AbandonedObjectPool(null,abandonedConfig); } else { gop = new GenericObjectPool(); } gop.setMaxActive(maxActive); gop.setMaxIdle(maxIdle); gop.setMinIdle(minIdle); gop.setMaxWait(maxWait); gop.setTestOnBorrow(testOnBorrow); gop.setTestOnReturn(testOnReturn); gop.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun); gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); gop.setTestWhileIdle(testWhileIdle); connectionPool = gop; }