当前位置: 首页>>代码示例>>Java>>正文


Java PooledDataSource.setPoolPingConnectionsNotUsedFor方法代码示例

本文整理汇总了Java中org.apache.ibatis.datasource.pooled.PooledDataSource.setPoolPingConnectionsNotUsedFor方法的典型用法代码示例。如果您正苦于以下问题:Java PooledDataSource.setPoolPingConnectionsNotUsedFor方法的具体用法?Java PooledDataSource.setPoolPingConnectionsNotUsedFor怎么用?Java PooledDataSource.setPoolPingConnectionsNotUsedFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ibatis.datasource.pooled.PooledDataSource的用法示例。


在下文中一共展示了PooledDataSource.setPoolPingConnectionsNotUsedFor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldProperlyMaintainPoolOf3ActiveAnd2IdleConnections

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
@Test
public void shouldProperlyMaintainPoolOf3ActiveAnd2IdleConnections() throws Exception {
  PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
  try {
    runScript(ds, JPETSTORE_DDL);
    ds.setDefaultAutoCommit(false);
    ds.setDriverProperties(new Properties() {
      {
        setProperty("username", "sa");
        setProperty("password", "");
      }
    });
    ds.setPoolMaximumActiveConnections(3);
    ds.setPoolMaximumIdleConnections(2);
    ds.setPoolMaximumCheckoutTime(10000);
    ds.setPoolPingConnectionsNotUsedFor(1);
    ds.setPoolPingEnabled(true);
    ds.setPoolPingQuery("SELECT * FROM PRODUCT");
    ds.setPoolTimeToWait(10000);
    ds.setLogWriter(null);
    List<Connection> connections = new ArrayList<Connection>();
    for (int i = 0; i < 3; i++) {
      connections.add(ds.getConnection());
    }
    assertEquals(3, ds.getPoolState().getActiveConnectionCount());
    for (Connection c : connections) {
      c.close();
    }
    assertEquals(2, ds.getPoolState().getIdleConnectionCount());
    assertEquals(4, ds.getPoolState().getRequestCount());
    assertEquals(0, ds.getPoolState().getBadConnectionCount());
    assertEquals(0, ds.getPoolState().getHadToWaitCount());
    assertEquals(0, ds.getPoolState().getAverageOverdueCheckoutTime());
    assertEquals(0, ds.getPoolState().getClaimedOverdueConnectionCount());
    assertEquals(0, ds.getPoolState().getAverageWaitTime());
    assertNotNull(ds.getPoolState().toString());
  } finally {
    ds.forceCloseAll();
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:41,代码来源:PooledDataSourceTest.java

示例2: shouldReconnectWhenServerKilledLeakedConnection

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
@Ignore("See the comments")
@Test
public void shouldReconnectWhenServerKilledLeakedConnection() throws Exception {
  // See #748
  // Requirements:
  // 1. MySQL JDBC driver dependency.
  // 2. MySQL server instance with the following.
  //  - CREATE DATABASE `test`;
  //  - SET GLOBAL wait_timeout=3;
  // 3. Tweak the connection info below.
  final String URL = "jdbc:mysql://localhost:3306/test";
  final String USERNAME = "admin";
  final String PASSWORD = "";

  Connection con;
  PooledDataSource ds = new PooledDataSource();
  ds.setDriver("com.mysql.jdbc.Driver");
  ds.setUrl(URL);
  ds.setUsername(USERNAME);
  ds.setPassword(PASSWORD);
  ds.setPoolMaximumActiveConnections(1);
  ds.setPoolMaximumIdleConnections(1);
  ds.setPoolTimeToWait(1000);
  ds.setPoolMaximumCheckoutTime(2000);
  ds.setPoolPingEnabled(true);
  ds.setPoolPingQuery("select 1");
  ds.setDefaultAutoCommit(true);
  // MySQL wait_timeout * 1000 or less. (unit:ms)
  ds.setPoolPingConnectionsNotUsedFor(1000);

  con = ds.getConnection();
  exexuteQuery(con);
  // Simulate connection leak by not closing.
  // con.close();

  // Wait for disconnected from mysql...
  Thread.sleep(TimeUnit.SECONDS.toMillis(3));

  // Should return usable connection.
  con = ds.getConnection();
  exexuteQuery(con);
  con.close();
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:44,代码来源:PooledDataSourceTest.java

示例3: initDataSource

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
protected void initDataSource() {
    if (dataSource == null) {
        if (dataSourceJndiName != null) {
            try {
                dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
            } catch (Exception e) {
                throw new FlowableException("couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
            }

        } else if (jdbcUrl != null) {
            if ((jdbcDriver == null) || (jdbcUsername == null)) {
                throw new FlowableException("DataSource or JDBC properties have to be specified in a process engine configuration");
            }

            LOGGER.debug("initializing datasource to db: {}", jdbcUrl);

            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Configuring Datasource with following properties (omitted password for security)");
                LOGGER.info("datasource driver : {}", jdbcDriver);
                LOGGER.info("datasource url : {}", jdbcUrl);
                LOGGER.info("datasource user name : {}", jdbcUsername);
            }

            PooledDataSource pooledDataSource = new PooledDataSource(this.getClass().getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword);

            if (jdbcMaxActiveConnections > 0) {
                pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
            }
            if (jdbcMaxIdleConnections > 0) {
                pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
            }
            if (jdbcMaxCheckoutTime > 0) {
                pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
            }
            if (jdbcMaxWaitTime > 0) {
                pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
            }
            if (jdbcPingEnabled) {
                pooledDataSource.setPoolPingEnabled(true);
                if (jdbcPingQuery != null) {
                    pooledDataSource.setPoolPingQuery(jdbcPingQuery);
                }
                pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
            }
            if (jdbcDefaultTransactionIsolationLevel > 0) {
                pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel);
            }
            dataSource = pooledDataSource;
        }

        if (dataSource instanceof PooledDataSource) {
            // ACT-233: connection pool of Ibatis is not properly
            // initialized if this is not called!
            ((PooledDataSource) dataSource).forceCloseAll();
        }
    }

    if (databaseType == null) {
        initDatabaseType();
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:62,代码来源:AbstractEngineConfiguration.java

示例4: initDataSource

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
protected void initDataSource() {
    if (dataSource == null) {
        if (dataSourceJndiName != null) {
            try {
                dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
            } catch (Exception e) {
                throw new ActivitiException("couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
            }

        } else if (jdbcUrl != null) {
            if ((jdbcDriver == null) || (jdbcUsername == null)) {
                throw new ActivitiException("DataSource or JDBC properties have to be specified in a process engine configuration");
            }

            LOGGER.debug("initializing datasource to db: {}", jdbcUrl);

            PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword);

            if (jdbcMaxActiveConnections > 0) {
                pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
            }
            if (jdbcMaxIdleConnections > 0) {
                pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
            }
            if (jdbcMaxCheckoutTime > 0) {
                pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
            }
            if (jdbcMaxWaitTime > 0) {
                pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
            }
            if (jdbcPingEnabled) {
                pooledDataSource.setPoolPingEnabled(true);
                if (jdbcPingQuery != null) {
                    pooledDataSource.setPoolPingQuery(jdbcPingQuery);
                }
                pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
            }
            if (jdbcDefaultTransactionIsolationLevel > 0) {
                pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel);
            }
            dataSource = pooledDataSource;
        }

        if (dataSource instanceof PooledDataSource) {
            // ACT-233: connection pool of Ibatis is not properly initialized if this is not called!
            ((PooledDataSource) dataSource).forceCloseAll();
        }
    }

    if (databaseType == null) {
        initDatabaseType();
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:54,代码来源:ProcessEngineConfigurationImpl.java

示例5: initDataSource

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
protected void initDataSource() {
  if (dataSource==null) {
    if (dataSourceJndiName!=null) {
      try {
        dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
      } catch (Exception e) {
        throw new ActivitiException("couldn't lookup datasource from "+dataSourceJndiName+": "+e.getMessage(), e);
      }
      
    } else if (jdbcUrl!=null) {
      if ( (jdbcDriver==null) || (jdbcUrl==null) || (jdbcUsername==null) ) {
        throw new ActivitiException("DataSource or JDBC properties have to be specified in a process engine configuration");
      }
      
      log.fine("initializing datasource to db: "+jdbcUrl);
      
      PooledDataSource pooledDataSource = 
        new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword );
      
      if (jdbcMaxActiveConnections > 0) {
        pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
      }
      if (jdbcMaxIdleConnections > 0) {
        pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
      }
      if (jdbcMaxCheckoutTime > 0) {
        pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
      }
      if (jdbcMaxWaitTime > 0) {
        pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
      }
      if (jdbcPingEnabled == true) {
        pooledDataSource.setPoolPingEnabled(true);
        if (jdbcPingQuery != null) {
          pooledDataSource.setPoolPingQuery(jdbcPingQuery);
        }
        pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
      }        
      dataSource = pooledDataSource;
    }
    
    if (dataSource instanceof PooledDataSource) {
      // ACT-233: connection pool of Ibatis is not properely initialized if this is not called!
      ((PooledDataSource)dataSource).forceCloseAll();
    }
  }

  if (databaseType == null) {
    initDatabaseType();
  }
}
 
开发者ID:logicalhacking,项目名称:SecureBPMN,代码行数:52,代码来源:ProcessEngineConfigurationImpl.java

示例6: initDataSource

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
protected void initDataSource() {
  if (dataSource==null) {
    if (dataSourceJndiName!=null) {
      try {
        dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
      } catch (Exception e) {
        throw new ActivitiException("couldn't lookup datasource from "+dataSourceJndiName+": "+e.getMessage(), e);
      }
      
    } else if (jdbcUrl!=null) {
      if ( (jdbcDriver==null) || (jdbcUrl==null) || (jdbcUsername==null) ) {
        throw new ActivitiException("DataSource or JDBC properties have to be specified in a process engine configuration");
      }
      
      log.debug("initializing datasource to db: {}", jdbcUrl);
      
      PooledDataSource pooledDataSource = 
        new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword );
      
      if (jdbcMaxActiveConnections > 0) {
        pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
      }
      if (jdbcMaxIdleConnections > 0) {
        pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
      }
      if (jdbcMaxCheckoutTime > 0) {
        pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
      }
      if (jdbcMaxWaitTime > 0) {
        pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
      }
      if (jdbcPingEnabled == true) {
        pooledDataSource.setPoolPingEnabled(true);
        if (jdbcPingQuery != null) {
          pooledDataSource.setPoolPingQuery(jdbcPingQuery);
        }
        pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
      }
      if (jdbcDefaultTransactionIsolationLevel > 0) {
        pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel);
      }
      dataSource = pooledDataSource;
    }
    
    if (dataSource instanceof PooledDataSource) {
      // ACT-233: connection pool of Ibatis is not properely initialized if this is not called!
      ((PooledDataSource)dataSource).forceCloseAll();
    }
  }

  if (databaseType == null) {
    initDatabaseType();
  }
}
 
开发者ID:springvelocity,项目名称:xbpm5,代码行数:55,代码来源:ProcessEngineConfigurationImpl.java

示例7: initDataSource

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
protected void initDataSource() {
  if (dataSource == null) {
    if (dataSourceJndiName != null) {
      try {
        dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);
      } catch (Exception e) {
        throw new ProcessEngineException("couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e);
      }

    } else if (jdbcUrl != null) {
      if ((jdbcDriver == null) || (jdbcUrl == null) || (jdbcUsername == null)) {
        throw new ProcessEngineException("DataSource or JDBC properties have to be specified in a process engine configuration");
      }

      PooledDataSource pooledDataSource =
          new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword);

      if (jdbcMaxActiveConnections > 0) {
        pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);
      }
      if (jdbcMaxIdleConnections > 0) {
        pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);
      }
      if (jdbcMaxCheckoutTime > 0) {
        pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime);
      }
      if (jdbcMaxWaitTime > 0) {
        pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime);
      }
      if (jdbcPingEnabled == true) {
        pooledDataSource.setPoolPingEnabled(true);
        if (jdbcPingQuery != null) {
          pooledDataSource.setPoolPingQuery(jdbcPingQuery);
        }
        pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor);
      }
      dataSource = pooledDataSource;
    }

    if (dataSource instanceof PooledDataSource) {
      // ACT-233: connection pool of Ibatis is not properely initialized if this is not called!
      ((PooledDataSource) dataSource).forceCloseAll();
    }
  }

  if (databaseType == null) {
    initDatabaseType();
  }
}
 
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:50,代码来源:ProcessEngineConfigurationImpl.java

示例8: shouldReconnectWhenServerKilledLeakedConnection

import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
@Ignore("See the comments")
@Test
public void shouldReconnectWhenServerKilledLeakedConnection() throws Exception {
  // See #748
  // Requirements:
  // 1. MySQL JDBC driver dependency.
  // 2. MySQL server instance with the following.
  //  - CREATE DATABASE `test`;
  //  - SET GLOBAL wait_timeout=3;
  // 3. Tweak the connection info below.
  final String URL = "jdbc:mysql://localhost:3306/test";
  final String USERNAME = "admin";
  final String PASSWORD = "";

  PooledDataSource ds = new PooledDataSource();
  ds.setDriver("com.mysql.jdbc.Driver");
  ds.setUrl(URL);
  ds.setUsername(USERNAME);
  ds.setPassword(PASSWORD);
  ds.setPoolMaximumActiveConnections(1);
  ds.setPoolMaximumIdleConnections(1);
  ds.setPoolTimeToWait(1000);
  ds.setPoolMaximumCheckoutTime(2000);
  ds.setPoolPingEnabled(true);
  ds.setPoolPingQuery("select 1");
  ds.setDefaultAutoCommit(true);
  // MySQL wait_timeout * 1000 or less. (unit:ms)
  ds.setPoolPingConnectionsNotUsedFor(1000);

  Connection con = ds.getConnection();
  exexuteQuery(con);
  // Simulate connection leak by not closing.
  // con.close();

  // Wait for disconnected from mysql...
  Thread.sleep(TimeUnit.SECONDS.toMillis(3));

  con.close();

  // Should return usable connection.
  con = ds.getConnection();
  exexuteQuery(con);
  con.close();
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:45,代码来源:PooledDataSourceTest.java


注:本文中的org.apache.ibatis.datasource.pooled.PooledDataSource.setPoolPingConnectionsNotUsedFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。