List of usage examples for org.apache.commons.pool.impl GenericObjectPool GenericObjectPool
public GenericObjectPool(PoolableObjectFactory factory)
From source file:com.ec2box.manage.util.DSPool.java
/** * register the data source for H2 DB/*from w w w .ja va2 s . c o m*/ * * @return pooling database object */ private static PoolingDataSource registerDataSource() { // create a database connection String user = "ec2box"; String password = "filepwd 0WJLnwhpA47EepT1A4drVnDn3vYRvJhpZi0sVdvN9SmlbKw"; String connectionURI = "jdbc:h2:" + getDBPath() + "/ec2box;CIPHER=AES;"; if (StringUtils.isNotEmpty(DB_OPTIONS)) { connectionURI = connectionURI + DB_OPTIONS; } String validationQuery = "select 1"; try { Class.forName("org.h2.Driver"); } catch (ClassNotFoundException ex) { log.error(ex.toString(), ex); } GenericObjectPool connectionPool = new GenericObjectPool(null); connectionPool.setMaxActive(MAX_ACTIVE); connectionPool.setTestOnBorrow(TEST_ON_BORROW); connectionPool.setMinIdle(MIN_IDLE); connectionPool.setMaxWait(MAX_WAIT); connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectionURI, user, password); new PoolableConnectionFactory(connectionFactory, connectionPool, null, validationQuery, false, true); return new PoolingDataSource(connectionPool); }
From source file:launcher.nub.multithread.Joiner.java
/** * Starts/*w ww . j a v a2 s. co m*/ */ protected void go() { GenericObjectPool pool = new GenericObjectPool(new JoinerFactory()); pool.setMaxActive(12); // wait forever pool.setMaxWait(-1); // hacktastic ;o) for (int i = 2; i < 1542; i++) { logger.info("Queing up Id: " + i); Thread t = new Thread(new Runner(taxonConceptDAO, taxonomyUtils, i, pool)); t.start(); } }
From source file:com.markhwood.jndi.EphemeralContext.objectProviders.CommonsDBCPDataSource.java
public Object interpret(String uri, String localName, String qName, Attributes attributes) { // FIXME where does wrapped datasource come in? GenericObjectPool connectionPool = new GenericObjectPool(null); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(attributes.getValue("url"), attributes.getValue("user"), attributes.getValue("password")); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); PoolingDataSource dataSource = new PoolingDataSource(connectionPool); return dataSource; }
From source file:edu.psu.citeseerx.dbcp.DBCPFactory.java
protected static DataSource setupDataSource(String connectURI, String username, String password) { org.apache.commons.pool.ObjectPool connectionPool = new GenericObjectPool(null); KeyedObjectPoolFactory stmtPoolFactory = null; // new GenericKeyedObjectPoolFactory(null); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, username, password); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, stmtPoolFactory, "select 1;", // validation query false, // default read/write false // default no autocommit );// w w w .j a va2s . c o m PoolingDataSource dataSource = new PoolingDataSource(connectionPool); return dataSource; }
From source file:com.nabla.wapp.server.database.CommonConnectionPool.java
/** * Load database pool//from w w w .j a v a2s. co m * @param name - database name as defined in pool */ public static void load(final String name) { if (log.isDebugEnabled()) log.debug("loading pool for database '" + name + "'"); driver.registerPool(name, new GenericObjectPool(null)); }
From source file:de.fct.companian.analyze.helper.DbHelper.java
public static DataSource createDataSource(Properties properties) { String dbDriver;/*from ww w .j av a 2 s. c o m*/ String dbUrl; String dbUser; String dbPass; String dbDriverDefault = "com.mysql.jdbc.Driver"; String dbUrlDefault = "jdbc:mysql://localhost:3306/cpanalyze"; String dbUserDefault = "cpanalyze"; String dbPassDefault = "ezylanapc"; if (properties != null) { dbDriver = properties.getProperty("database.driver"); if (dbDriver == null) { dbDriver = dbDriverDefault; } dbUrl = properties.getProperty("database.url"); if (dbUrl == null) { dbUrl = dbUrlDefault; } dbUser = properties.getProperty("database.username"); if (dbUser == null) { dbUser = dbUserDefault; } dbPass = properties.getProperty("database.password"); if (dbPass == null && dbUser.equals("cpanalyze")) { dbPass = dbPassDefault; } } else { dbDriver = dbDriverDefault; dbUrl = dbUrlDefault; dbUser = dbUserDefault; dbPass = dbPassDefault; } logger.debug("createDataSource() loading underlying JDBC driver."); try { Class.forName(dbDriver); } catch (ClassNotFoundException e) { e.printStackTrace(); } ObjectPool connectionPool = new GenericObjectPool(null); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dbUrl, dbUser, dbPass); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); PoolingDataSource ds = new PoolingDataSource(connectionPool); if (ds == null) { logger.error("createDataSource() could not create data source"); } return ds; }
From source file:com.aaasec.sigserv.cscommon.SqLiteConnectionPool.java
private static DataSource setupDataSource(String connectURI, String userName, String password) { ObjectPool connectionPool = new GenericObjectPool(null); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI, userName, password); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); PoolingDataSource dataSource = new PoolingDataSource(connectionPool); return dataSource; }
From source file:com.centurylink.mdw.services.pooling.MDWConnectionPool.java
/** * This can be overriden to set pool size and borrow timeout * for each start/restart./*from w w w .j av a 2 s . c o m*/ * The super method must be called at the end of the overriding method. * @throws Exception */ public synchronized void start() throws Exception { if (pool == null) { pool = new GenericObjectPool(new MDWPoolFactory()); } pool.setMaxActive(pool_size); if (borrow_timeout < 0) { pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); pool.setMaxWait(-1); } else if (borrow_timeout == 0) { pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_FAIL); pool.setMaxWait(0); } else { pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); pool.setMaxWait(borrow_timeout * 1000); } setStarted(true); }
From source file:com.cisco.dvbu.ps.common.adapters.connect.AdapterConnectionPool.java
public synchronized void init(Connector conn) { if (pool != null) return;//from w ww.ja va2s.c o m pool = new GenericObjectPool(new AdapterConnectionPoolFactory(conn)); pool.setTimeBetweenEvictionRunsMillis(1000 * 60 * 5); // 5 minutes pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); pool.setMaxActive((connConfig != null) ? connConfig.getMaxClients() : 5); pool.setMinIdle((connConfig != null) ? connConfig.getMinClients() : 3); pool.setMaxIdle((connConfig != null) ? connConfig.getMinClients() : 3); pool.setMaxWait(1000 * 60 * 5); // 5 minutes pool.setSoftMinEvictableIdleTimeMillis(1000 * 60 * 60); pool.setNumTestsPerEvictionRun(2); }
From source file:launcher.multithread.Extract.java
/** * Starts/*from w w w.java 2 s .com*/ */ protected void go() { GenericObjectPool pool = new GenericObjectPool(new ExtractorFactory()); pool.setMaxActive(15); // wait forever pool.setMaxWait(-1); // hacktastic ;o) /* int[] rapIds = {218,67,92,26,497,374,1858,1039,429,716}; for(int i=0; i<rapIds.length; i++) { int rapId = rapIds[i]; */ for (int rapId = 0; rapId < 2000; rapId++) { // these have been done... if (rapId == 218 || rapId == 67 || rapId == 92 || rapId == 26 || rapId == 497 || rapId == 374 || rapId == 1858 || rapId == 1039 || rapId == 429 || rapId == 716) { continue; } logger.info("Queing up Id: " + rapId); SequenceProcessor workflow = (SequenceProcessor) context.getBean("GBIF:INDEX:1.0:extractOccurrence"); Map<String, Object> seed = new HashMap<String, Object>(); GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.MONTH, -6); seed.put("pageFrom", cal.getTime()); seed.put("resourceAccessPointId", new Long(rapId)); Thread t = new Thread(new Runner(seed, workflow, pool)); t.start(); } }