List of usage examples for org.apache.commons.pool2 ObjectPool returnObject
void returnObject(T obj) throws Exception;
From source file:co.edu.unbosque.swii.PoolTest.java
@Test public void quePasaCuandoSeRetornaUnaconexionContransaccionIniciada() throws Exception { FabricaConexiones fc = new FabricaConexiones("aretico.com", 5432, "software_2", "grupo7_5", pwd); ObjectPool<Connection> pool = new GenericObjectPool<Connection>(fc); Connection c = pool.borrowObject(); c.close();//from w w w. j a v a 2 s. c o m pool.returnObject(c); }
From source file:co.edu.unbosque.swii.PoolTest.java
@Test public void aprendiendoAControlarLasConexiones() throws Exception { FabricaConexiones fc = new FabricaConexiones("aretico.com", 5432, "software_2", "grupo7_5", pwd); ObjectPool<Connection> pool = new GenericObjectPool<Connection>(fc); for (int i = 0; i < 6; i++) { Connection c = pool.borrowObject(); pool.returnObject(c); }//from w w w . j a v a 2s . c o m }
From source file:co.edu.unbosque.swii.PoolTest.java
@Test public void quePasaCuandoSeCierraUnaConexionAntesDeRetornarla() throws Exception { FabricaConexiones fc = new FabricaConexiones("aretico.com", 5432, "software_2", "grupo7_5", pwd); ObjectPool<Connection> pool = new GenericObjectPool<Connection>(fc); for (int i = 0; i < 6; i++) { Connection c = pool.borrowObject(); pool.returnObject(c); }//from ww w .ja v a 2 s. c om }
From source file:com.mirth.connect.connectors.file.FileConnector.java
/** * Return a connection to the pool// ww w .j a v a2 s .com * * @param uri * The URI of the endpoint from which the connection is being released. * @param client * The connection that is being released. * @param message * ?? * @throws Exception */ protected void releaseConnection(FileSystemConnection connection, FileSystemConnectionOptions fileSystemOptions) throws Exception { // if (isCreateDispatcherPerRequest()) { // destroyConnection(uri, connection, message); // } else { synchronized (connections) { connections.remove(connection); } if (connection != null && connection.isConnected()) { ObjectPool<FileSystemConnection> pool = getConnectionPool(fileSystemOptions); pool.returnObject(connection); } // } }
From source file:co.edu.unbosque.swii.PoolTest.java
@Test(threadPoolSize = 5, invocationCount = 5) public void midaTiemposParaInsertar1000RegistrosConSingleton() throws ClassNotFoundException, SQLException, Exception { long tiempo = System.currentTimeMillis(); String SQL;/*from w ww .j a va 2 s . c om*/ for (int x = 0; x < 1000; x++) { FabricaConexiones fc = new FabricaConexiones("aretico.com", 5432, "software_2", "grupo7_5", pwd); ObjectPool<Connection> pool = new GenericObjectPool<Connection>(fc); Connection c = pool.borrowObject(); SQL = "INSERT INTO grupo7.RegistroHilos( registro, hilo, fecha) VALUES (?, ?, now());"; PreparedStatement parametros = c.prepareStatement(SQL); parametros.setInt(1, x); parametros.setInt(2, (int) Thread.currentThread().getId()); parametros.executeUpdate(); pool.returnObject(c); } System.out.println("Tiempo de ejecucion " + (System.currentTimeMillis() - tiempo)); }
From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java
private void borrowAndReturn(ObjectPool<StatefulRedisConnection<String, String>> pool) throws Exception { for (int i = 0; i < 10; i++) { StatefulRedisConnection<String, String> connection = pool.borrowObject(); RedisCommands<String, String> sync = connection.sync(); sync.ping();/*from ww w . j a v a 2 s . c o m*/ pool.returnObject(connection); } }
From source file:stroom.pool.AbstractPoolCacheBean.java
@Override public void returnObject(final PoolItem<K, V> poolItem, final boolean usePool) { if (usePool) { try {//from www.j av a 2 s .c o m final K key = poolItem.getKey(); final ObjectPool<PoolItem<K, V>> pool = getQuiet(key); if (pool != null) { pool.returnObject(poolItem); } } catch (final Exception e) { throw new RuntimeException(e.getMessage(), e); } } }