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


Java HikariPool类代码示例

本文整理汇总了Java中com.zaxxer.hikari.pool.HikariPool的典型用法代码示例。如果您正苦于以下问题:Java HikariPool类的具体用法?Java HikariPool怎么用?Java HikariPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: configureConnPool

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
/**
 * Configures the connection pool
 *
 * @return true if the connection pool was setup correctly, false otherwise
 * @since 4.0.6
 */
boolean configureConnPool() {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();

    try {
        Class.forName("com.mysql.jdbc.Driver"); //also you need the MySQL driver
        plugin.getLogger().info("Creating HikariCP Configuration...");
        HikariConfig hikariConfig = new HikariConfig();

        hikariConfig.setJdbcUrl(config.getString("stats.database.address"));
        hikariConfig.setUsername(config.getString("stats.database.user"));
        hikariConfig.setPassword(config.getString("stats.database.password"));
        hikariConfig.setMaximumPoolSize(config.getInt("stats.database.maximum-pool-size"));

        plugin.getLogger().info("Setting up MySQL Connection pool...");
        connectionPool = new HikariPool(hikariConfig); // setup the connection pool
        plugin.getLogger().info("Connection pool successfully configured. ");
    } catch (ClassNotFoundException e) {
    	plugin.getLogger().info("Connection failed! Returning to file stats.");
        e.printStackTrace(); //you should use exception wrapping on real-production code
        return false;
    }

    return true;
}
 
开发者ID:stefvanschie,项目名称:buildinggame,代码行数:31,代码来源:ConnectionManager.java

示例2: testDerbyDataSource

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
@Test
public void testDerbyDataSource() throws SQLException {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT.yml")
            .autoLoadModules()
            .createRuntime();

    DataSource ds4 = runtime.getInstance(DataSourceFactory.class).forName("derby4");
    assertNotNull(ds4);
    assertTrue(ds4 instanceof HikariDataSource);

    HikariDataSource hikariDS = (HikariDataSource) ds4;

    assertEquals("org.apache.derby.jdbc.EmbeddedDataSource", hikariDS.getDataSourceClassName());

    HikariPool pool = (HikariPool) hikariDS.getHikariPoolMXBean();

    assertTrue(pool.getUnwrappedDataSource().getClass().isAssignableFrom(EmbeddedDataSource.class));

    try (Connection c = hikariDS.getConnection()) {
        assertEquals("jdbc:derby:target/derby4", c.getMetaData().getURL());
    }
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:23,代码来源:HikariCPDerbyIT.java

示例3: testDerbyDriverDataSource

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
@Test
public void testDerbyDriverDataSource() throws SQLException {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT.yml")
            .autoLoadModules()
            .createRuntime();

    DataSource ds5 = runtime.getInstance(DataSourceFactory.class).forName("derby5");
    assertNotNull(ds5);
    assertTrue(ds5 instanceof HikariDataSource);

    HikariDataSource hikariDS = (HikariDataSource) ds5;

    assertEquals("org.apache.derby.jdbc.EmbeddedDriver", hikariDS.getDriverClassName());

    HikariPool pool = (HikariPool) hikariDS.getHikariPoolMXBean();

    assertTrue(pool.getUnwrappedDataSource() instanceof DriverDataSource);

    try (Connection c = hikariDS.getConnection()) {
        assertEquals("jdbc:derby:", c.getMetaData().getURL());
    }
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:23,代码来源:HikariCPDerbyIT.java

示例4: list

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
public void list() {

        System.out.print(String.format("%1$15s", "DataSource"));
        System.out.print(String.format("%1$15s", "Max Cn"));
        System.out.print(String.format("%1$15s", "Active Cn"));
        System.out.print(String.format("%1$15s", "Free Cn"));
        System.out.print(String.format("%1$15s", "Cn Wait"));
        System.out.print("\n");

        for (Map.Entry<String, HikariDataSource> entry : dbMap.entrySet()) {
            HikariPool pool = getPool(entry.getValue());

            int totalConnections = pool.getTotalConnections();
            int activeConnections = pool.getActiveConnections();
            int freeConnections = totalConnections - activeConnections;
            int connectionWaiting = pool.getThreadsAwaitingConnection();

            System.out.print(String.format("%1$15s", entry.getKey()));
            System.out.print(String.format("%1$15s", totalConnections));
            System.out.print(String.format("%1$15s", activeConnections));
            System.out.print(String.format("%1$15s", freeConnections));
            System.out.print(String.format("%1$15s", connectionWaiting));
            System.out.print("\n");
        }
    }
 
开发者ID:kscarr73,项目名称:OsgiDb,代码行数:26,代码来源:DbActivator.java

示例5: testShutdown5

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
@Test
public void testShutdown5() throws SQLException
{
   Assert.assertSame("StubConnection count not as expected", 0, StubConnection.count.get());

   HikariConfig config = new HikariConfig();
   config.setMinimumIdle(5);
   config.setMaximumPoolSize(5);
   config.setInitializationFailFast(true);
   config.setConnectionTestQuery("VALUES 1");
   config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");

   HikariDataSource ds = new HikariDataSource(config);
   HikariPool pool = TestElf.getPool(ds);

   Connection[] connections = new Connection[5];
   for (int i = 0; i < 5; i++) {
      connections[i] = ds.getConnection();
   }

   Assert.assertTrue("Totals connection count not as expected, ", pool.getTotalConnections() == 5);

   ds.close();

   Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections());
   Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections());
   Assert.assertSame("Total connection count not as expected", 0, pool.getTotalConnections());
}
 
开发者ID:openbouquet,项目名称:HikariCP,代码行数:29,代码来源:ShutdownTest.java

示例6: HikariCpConfig

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
private HikariCpConfig(final JsonObject config) {

        final HikariConfig hikariConfig = new HikariConfig();
        // Init hikariCp, refer to offical site
        // https://github.com/brettwooldridge/HikariCP
        hikariConfig.setDriverClassName(config.getString("driverClassName"));
        hikariConfig.setJdbcUrl(config.getString("jdbcUrl"));
        hikariConfig.setUsername(config.getString("username"));
        hikariConfig.setPassword(config.getString("password"));
        hikariConfig.setCatalog(config.getString("catalog"));
        // Init data source
        final HikariDataSource dataSource = new HikariDataSource(hikariConfig);
        this.pool = new HikariPool(dataSource);
    }
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:15,代码来源:HikariCpConfig.java

示例7: retriableDataSource

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
/**
 * Attempts to create a {@link HikariDataSource} by making an initial connection to the database.
 * Retries a number of times, with a delay between each retry, according to the provided {@link PatterdaleRuntimeParameters}.
 *
 * Failed attempts are logged as well as when the number of retries has exceeded.
 *
 * @param runtimeParams The app configuration defined in `patterdale.yml`.
 * @param databaseDefinition The details of the database being connected to.
 * @param passwords The separate store of passwords, the matching password will be found according to the `databaseDefinition`.
 * @param logger to log.
 * @return A data source for a successful connection to the database.
 */
public static HikariDataSource retriableDataSource(PatterdaleRuntimeParameters runtimeParams, DatabaseDefinition databaseDefinition, Passwords passwords, Logger logger) {
    RetryPolicy retryPolicy = new RetryPolicy()
            .retryOn(HikariPool.PoolInitializationException.class)
            .withDelay(runtimeParams.connectionRetryDelayInSeconds(), TimeUnit.SECONDS)
            .withMaxRetries(runtimeParams.maxConnectionRetries());

    return Failsafe.with(retryPolicy)
            .onRetry((result, failure, context) -> logRetry(runtimeParams, databaseDefinition, logger))
            .onFailedAttempt((result, failure, context) -> logFailedAttempt(databaseDefinition, logger))
            .onRetriesExceeded(throwable -> logRetriesExceeded(databaseDefinition, logger))
            .get(() -> dataSource(runtimeParams, databaseDefinition, passwords, logger));
}
 
开发者ID:tjheslin1,项目名称:Patterdale,代码行数:25,代码来源:HikariDataSourceProvider.java

示例8: HikariDataSource

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
/**
 * Construct a HikariDataSource with the specified configuration.
 *
 * @param configuration a HikariConfig instance
 */
public HikariDataSource(HikariConfig configuration)
{
   configuration.validate();
   configuration.copyState(this);

   LOGGER.info("{} - is starting.", configuration.getPoolName());
   pool = fastPathPool = new HikariPool(this);
}
 
开发者ID:openbouquet,项目名称:HikariCP,代码行数:14,代码来源:HikariDataSource.java

示例9: getConnection

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public Connection getConnection() throws SQLException
{
   if (isClosed()) {
      throw new SQLException("HikariDataSource " + this + " has been closed.");
   }

   if (fastPathPool != null) {
      return fastPathPool.getConnection();
   }

   // See http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
   HikariPool result = pool;
   if (result == null) {
      synchronized (this) {
         result = pool;
         if (result == null) {
            validate();
            LOGGER.info("{} - is starting.", getPoolName());
            pool = result = new HikariPool(this);
         }
      }
   }

   return result.getConnection();
}
 
开发者ID:openbouquet,项目名称:HikariCP,代码行数:28,代码来源:HikariDataSource.java

示例10: testShutdown2

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
@Test
public void testShutdown2() throws SQLException
{
   Assert.assertSame("StubConnection count not as expected", 0, StubConnection.count.get());

   StubConnection.slowCreate = true;

   HikariConfig config = new HikariConfig();
   config.setMinimumIdle(10);
   config.setMaximumPoolSize(10);
   config.setInitializationFailFast(true);
   config.setConnectionTestQuery("VALUES 1");
   config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");

   HikariDataSource ds = new HikariDataSource(config);
   HikariPool pool = TestElf.getPool(ds);

   UtilityElf.quietlySleep(1200L);

   Assert.assertTrue("Totals connection count not as expected, ", pool.getTotalConnections() > 0);

   ds.close();

   Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections());
   Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections());
   Assert.assertSame("Total connection count not as expected", 0, pool.getTotalConnections());
   Assert.assertTrue(ds.toString().startsWith("HikariDataSource (") && ds.toString().endsWith(")"));
}
 
开发者ID:openbouquet,项目名称:HikariCP,代码行数:29,代码来源:ShutdownTest.java

示例11: testShutdown3

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
@Test
public void testShutdown3() throws SQLException
{
   Assert.assertSame("StubConnection count not as expected", 0, StubConnection.count.get());

   StubConnection.slowCreate = false;
   
   HikariConfig config = new HikariConfig();
   config.setMinimumIdle(5);
   config.setMaximumPoolSize(5);
   config.setInitializationFailFast(true);
   config.setConnectionTestQuery("VALUES 1");
   config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");

   HikariDataSource ds = new HikariDataSource(config);
   HikariPool pool = TestElf.getPool(ds);

   UtilityElf.quietlySleep(1200L);

   Assert.assertTrue("Totals connection count not as expected, ", pool.getTotalConnections() == 5);

   ds.close();

   Assert.assertSame("Active connection count not as expected, ", 0, pool.getActiveConnections());
   Assert.assertSame("Idle connection count not as expected, ", 0, pool.getIdleConnections());
   Assert.assertSame("Total connection count not as expected", 0, pool.getTotalConnections());
}
 
开发者ID:openbouquet,项目名称:HikariCP,代码行数:28,代码来源:ShutdownTest.java

示例12: testLeakDetection

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
@Test
public void testLeakDetection() throws SQLException
{
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   PrintStream ps = new PrintStream(baos, true);
   TestElf.setSlf4jTargetStream(LeakTask.class, ps);

   HikariConfig config = new HikariConfig();
   config.setMinimumIdle(0);
   config.setMaximumPoolSize(4);
   config.setPoolName("test");
   config.setThreadFactory(Executors.defaultThreadFactory());
   config.setMetricRegistry(null);
   config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(1));
   config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
   TestElf.setConfigUnitTest(true);

   final HikariDataSource ds = new HikariDataSource(config);
   try {
      TestElf.setSlf4jLogLevel(HikariPool.class, LocationAwareLogger.DEBUG_INT);
      TestElf.getPool(ds).logPoolState();

      Connection connection = ds.getConnection();
      UtilityElf.quietlySleep(TimeUnit.SECONDS.toMillis(4));
      connection.close();
      UtilityElf.quietlySleep(TimeUnit.SECONDS.toMillis(1));
      ps.close();
      String s = new String(baos.toByteArray());
      Assert.assertNotNull("Exception string was null", s);
      Assert.assertTrue("Expected exception to contain 'Apparent connection leak detected' but contains *" + s + "*", s.contains("Apparent connection leak detected"));
   }
   finally
   {
      TestElf.setConfigUnitTest(false);
      ds.close();
   }
}
 
开发者ID:openbouquet,项目名称:HikariCP,代码行数:38,代码来源:MiscTest.java

示例13: getPool

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
public static HikariPool getPool(HikariDataSource ds)
{
   try {
      Field field = ds.getClass().getDeclaredField("pool");
      field.setAccessible(true);
      return (HikariPool) field.get(ds);
   }
   catch (Exception e) {
      throw new RuntimeException(e);
   }
}
 
开发者ID:openbouquet,项目名称:HikariCP,代码行数:12,代码来源:TestElf.java

示例14: getMultiPool

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static HashMap<Object, HikariPool> getMultiPool(HikariDataSource ds)
{
   try {
      Field field = ds.getClass().getDeclaredField("multiPool");
      field.setAccessible(true);
      return (HashMap<Object, HikariPool>) field.get(ds);
   }
   catch (Exception e) {
      throw new RuntimeException(e);
   }
}
 
开发者ID:openbouquet,项目名称:HikariCP,代码行数:13,代码来源:TestElf.java

示例15: getPool

import com.zaxxer.hikari.pool.HikariPool; //导入依赖的package包/类
public HikariPool getPool(HikariDataSource ds) {
    try {
        Field field = ds.getClass().getDeclaredField("pool");
        field.setAccessible(true);
        return (HikariPool) field.get(ds);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:kscarr73,项目名称:OsgiDb,代码行数:10,代码来源:DbActivator.java


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