Java Code Examples for org.apache.tomcat.jdbc.pool.PoolProperties#setMaxIdle()
The following examples show how to use
org.apache.tomcat.jdbc.pool.PoolProperties#setMaxIdle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DFDbUtil.java From dfactor with MIT License | 5 votes |
public static DataSource createMysqlDbSource(String url, String user, String pwd, int initSize, int maxActive, int maxWait, int maxIdle, int minIdle){ PoolProperties p = new PoolProperties(); p.setDriverClassName("com.mysql.jdbc.Driver"); p.setUrl(url); p.setUsername(user); p.setPassword(pwd); p.setJmxEnabled(true); p.setTestWhileIdle(true); p.setTestOnBorrow(false); p.setTestOnReturn(false); p.setValidationQuery("SELECT 1"); p.setValidationInterval(30000); p.setTimeBetweenEvictionRunsMillis(30000); p.setMaxActive(maxActive); p.setInitialSize(initSize); p.setMaxWait(maxWait); //conn timeout p.setRemoveAbandonedTimeout(60); p.setMinEvictableIdleTimeMillis(30000); p.setMaxIdle(maxIdle); p.setMinIdle(minIdle); p.setLogAbandoned(true); p.setRemoveAbandoned(true); p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+ "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); final DataSource dbSrc = new DataSource(); dbSrc.setPoolProperties(p); return dbSrc; }
Example 2
Source File: TestTomcatJdbcPoolBehavior.java From aceql-http with GNU Lesser General Public License v2.1 | 5 votes |
public static void createPool() throws Exception { // Modify this code in order to extract a Connection from your // connection pooling system: // Driver parameters to use: String driverClassName = "org.postgresql.Driver"; String url = "jdbc:postgresql://localhost:5432/sampledb"; String username = "user1"; String password = "password1"; // Creating the DataSource bean and populating the values: // Mandatory values to set PoolProperties p = new PoolProperties(); p.setDriverClassName(driverClassName); p.setUrl(url); p.setUsername(username); p.setPassword(password); // Other possible values to set p.setTestOnBorrow(true); p.setValidationQuery("SELECT 1"); p.setTestOnReturn(false); p.setValidationInterval(30000); p.setTimeBetweenEvictionRunsMillis(30000); p.setMaxActive(2); p.setInitialSize(2); p.setMaxWait(10000); p.setRemoveAbandonedTimeout(60); p.setMinEvictableIdleTimeMillis(30000); p.setMinIdle(2); p.setMaxIdle(2); p.setLogAbandoned(true); p.setRemoveAbandoned(true); p.setJdbcInterceptors("ConnectionState;StatementFinalizer"); dataSource = new DataSource(); dataSource.setPoolProperties(p); }
Example 3
Source File: TomcatJdbcDataSourcePool.java From Zebra with Apache License 2.0 | 4 votes |
@Override public DataSource build(DataSourceConfig config, boolean withDefaultValue) { PoolProperties properties = new PoolProperties(); properties.setUrl(config.getJdbcUrl()); properties.setUsername(config.getUsername()); properties.setPassword(config.getPassword()); properties.setDriverClassName(JdbcDriverClassHelper.getDriverClassNameByJdbcUrl(config.getJdbcUrl())); if (withDefaultValue) { properties.setInitialSize(getIntProperty(config, "initialPoolSize", 5)); properties.setMaxActive(getIntProperty(config, "maxPoolSize", 30)); properties.setMinIdle(getIntProperty(config, "minPoolSize", 5)); properties.setMaxIdle(getIntProperty(config, "maxPoolSize", 20)); properties.setMaxWait(getIntProperty(config, "checkoutTimeout", 1000)); properties.setValidationQuery(getStringProperty(config, "preferredTestQuery", "SELECT 1")); properties.setMinEvictableIdleTimeMillis(getIntProperty(config, "minEvictableIdleTimeMillis", 300000));// 5min properties.setTimeBetweenEvictionRunsMillis(getIntProperty(config, "timeBetweenEvictionRunsMillis", 30000)); // 30s properties.setNumTestsPerEvictionRun(getIntProperty(config, "numTestsPerEvictionRun", 6)); properties.setValidationQueryTimeout(getIntProperty(config, "validationQueryTimeout", 0)); properties.setValidationInterval(getIntProperty(config, "validationInterval", 30000));// 30s properties.setRemoveAbandonedTimeout(getIntProperty(config, "removeAbandonedTimeout", 300)); if (StringUtils.isNotBlank(getStringProperty(config, "connectionInitSql", null))) { properties.setInitSQL(getStringProperty(config, "connectionInitSql", null)); } properties.setTestWhileIdle(true); properties.setTestOnBorrow(false); properties.setTestOnReturn(false); properties.setRemoveAbandoned(true); } else { try { PropertiesInit<PoolProperties> propertiesInit = new PropertiesInit<PoolProperties>(properties); propertiesInit.initPoolProperties(config); } catch (Exception e) { throw new ZebraConfigException( String.format("tomcat-jdbc dataSource [%s] created error : ", config.getId()), e); } } org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource(); datasource.setPoolProperties(properties); this.pool = datasource; LOGGER.info(String.format("New dataSource [%s] created.", config.getId())); return this.pool; }