List of usage examples for org.apache.commons.pool.impl GenericObjectPool close
public void close() throws Exception
From source file:Pool162.java
public void testWhenExhaustedBlockInterupt() throws Exception { GenericObjectPool pool = new GenericObjectPool(new SimpleFactory()); //Set this value to 1 to get the deadlock. No deadlock when it sets to //other values. pool.setMaxActive(2);/* w w w . ja va 2 s. c o m*/ pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); Object obj1 = pool.borrowObject(); // Make sure one object was obtained if (obj1 == null) { throw new Exception("obj1 is null"); } // Create a separate thread to try and borrow another object WaitingTestThread wtt = new WaitingTestThread(pool, 200); wtt.start(); // Give wtt time to start Thread.sleep(200); //bug trigger #1 wtt.interrupt(); //bug trigger #1 // Give interrupt time to take effect Thread.sleep(200); // Return object to the pool pool.returnObject(obj1); Object obj2 = null; obj2 = pool.borrowObject(); if (obj2 == null) { throw new Exception("obj2 is null"); } pool.returnObject(obj2); pool.close(); }
From source file:net.sf.farrago.namespace.jdbc.MedJdbcDataServer.java
public void closeAllocation() { closeConnection();//w ww . j ava 2s. c o m if (connectionPool != null) { try { dataSource = null; GenericObjectPool pool = connectionPool; connectionPool = null; pool.close(); } catch (Exception e) { logger.log(Level.SEVERE, "Error closing connection pool", e); } } }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java
public void testExceptionOnPassivateDuringReturn() throws Exception { SimpleFactory factory = new SimpleFactory(); GenericObjectPool pool = new GenericObjectPool(factory); Object obj = pool.borrowObject(); factory.setThrowExceptionOnPassivate(true); pool.returnObject(obj);/*from w ww . j ava 2s . co m*/ assertEquals(0, pool.getNumIdle()); pool.close(); }
From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java
/** * Tests addObject contention between ensureMinIdle triggered by the Evictor * with minIdle > 0 and borrowObject. *///from w ww . ja v a 2s .c om public void testEvictAddObjects() throws Exception { SimpleFactory factory = new SimpleFactory(); factory.setMakeLatency(300); factory.setMaxActive(2); GenericObjectPool pool = new GenericObjectPool(factory); pool.setMaxActive(2); pool.setMinIdle(1); pool.borrowObject(); // numActive = 1, numIdle = 0 // Create a test thread that will run once and try a borrow after // 150ms fixed delay TestThread borrower = new TestThread(pool, 1, 150, false); Thread borrowerThread = new Thread(borrower); // Set evictor to run in 100 ms - will create idle instance pool.setTimeBetweenEvictionRunsMillis(100); borrowerThread.start(); // Off to the races borrowerThread.join(); assertTrue(!borrower.failed()); pool.close(); }
From source file:org.alinous.plugin.mysql.MySQLDataSource.java
public void dispose() { GenericObjectPool pool = this.connectionPool; this.connectionPool = null; pool.clear();/* ww w. j a va2 s. c om*/ try { pool.close(); } catch (Exception e) { e.printStackTrace(); } AlinousDebug.debugOut(core, "Disposed mysql pool.............."); }
From source file:org.cipango.sipatra.DefaultContextLoader.java
protected void stopPool(GenericObjectPool pool) { pool.clear();//from w w w . jav a 2 s.c o m try { pool.close(); } catch (Exception e) { _log.error("ERROR >> Failed to close pool ", e); } }
From source file:org.idevlab.rjc.ds.PoolableDataSource.java
public synchronized void close() { closed = true;//w ww . j a v a2s.c o m GenericObjectPool oldPool = connectionPool; connectionPool = null; try { if (oldPool != null) { oldPool.close(); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RedisException("Cannot close connection pool", e); } }
From source file:org.onecmdb.core.utils.transform.jdbc.ClassLoaderBasicDataSource.java
/** * Close and release all connections that are currently stored in the * connection pool associated with our data source. * * @throws SQLException if a database error occurs */// w w w . j a va 2 s .c o m public synchronized void close() throws SQLException { GenericObjectPool oldpool = connectionPool; connectionPool = null; dataSource = null; try { if (oldpool != null) { oldpool.close(); } } catch (SQLException e) { throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Cannot close connection pool", e); } }