Package com.zaxxer.hikari.pool

Examples of com.zaxxer.hikari.pool.HikariPool


      configuration.validate();
      configuration.copyState(this);
      multiPool = new HashMap<MultiPoolKey, HikariPool>();

      LOGGER.info("HikariCP pool {} is starting.", configuration.getPoolName());
      pool = fastPathPool = new HikariPool(this);
      multiPool.put(new MultiPoolKey(getUsername(), getPassword()), pool);
   }
View Full Code Here


      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("HikariCP pool {} is starting.", getPoolName());
               pool = result = new HikariPool(this);
               multiPool.put(new MultiPoolKey(getUsername(), getPassword()), pool);
            }
         }
      }

      return result.getConnection();
   }
View Full Code Here

         throw new SQLException("Pool has been shutdown");
      }

      final MultiPoolKey key = new MultiPoolKey(username, password);

      HikariPool hikariPool;
      synchronized (multiPool) {
         hikariPool = multiPool.get(key);
         if (hikariPool == null) {
            hikariPool = new HikariPool(this, username, password);
            multiPool.put(key, hikariPool);
         }
      }

      return hikariPool.getConnection();
   }
View Full Code Here

   /** {@inheritDoc} */
   @Override
   public int getLoginTimeout() throws SQLException
   {
      HikariPool hikariPool = multiPool.values().iterator().next();
      if (hikariPool != null) {
         return hikariPool.getDataSource().getLoginTimeout();
      }

      return 0;
   }
View Full Code Here

      config.setInitializationFailFast(false);
      config.setConnectionTestQuery("VALUES 1");
      config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");

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

      Thread[] threads = new Thread[10];
      for (int i = 0; i < 10; i++) {
         threads[i] = new Thread() {
            public void run()
            {
               try {
                  if (ds.getConnection() != null) {
                     PoolUtilities.quietlySleep(TimeUnit.SECONDS.toMillis(1));
                  }
               }
               catch (SQLException e) {
               }
            }
         };
         threads[i].setDaemon(true);
         threads[i].start();
      }

      PoolUtilities.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());
   }
View Full Code Here

      config.setInitializationFailFast(false);
      config.setConnectionTestQuery("VALUES 1");
      config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");

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

      PoolUtilities.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());
   }
View Full Code Here

      config.setInitializationFailFast(true);
      config.setConnectionTestQuery("VALUES 1");
      config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");

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

      PoolUtilities.quietlySleep(500L);

      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());
   }
View Full Code Here

      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());
   }
View Full Code Here

TOP

Related Classes of com.zaxxer.hikari.pool.HikariPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.