當前位置: 首頁>>代碼示例>>Java>>正文


Java HikariConfig.setMaximumPoolSize方法代碼示例

本文整理匯總了Java中com.zaxxer.hikari.HikariConfig.setMaximumPoolSize方法的典型用法代碼示例。如果您正苦於以下問題:Java HikariConfig.setMaximumPoolSize方法的具體用法?Java HikariConfig.setMaximumPoolSize怎麽用?Java HikariConfig.setMaximumPoolSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.zaxxer.hikari.HikariConfig的用法示例。


在下文中一共展示了HikariConfig.setMaximumPoolSize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Database

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
public Database() {
    try {
        Class.forName("org.mariadb.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(App.getConfig().getString("database.url"));
    config.setUsername(App.getConfig().getString("database.user"));
    config.setPassword(App.getConfig().getString("database.pass"));
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    config.addDataSourceProperty("allowMultiQueries", "true");
    config.setMaximumPoolSize(200); // this is plenty, the websocket uses 32

    dbi = new DBI(new HikariDataSource(config));
    

    getHandle().createPixelsTable();
    getHandle().createUsersTable();
    getHandle().createSessionsTable();
    getHandle().createAdminLogTable();
    getHandle().createReportsTable();
}
 
開發者ID:xSke,項目名稱:Pxls,代碼行數:27,代碼來源:Database.java

示例2: HikariWrapper

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
public HikariWrapper(@Nonnull DatabaseCredentials credentials) {
    HikariConfig config = new HikariConfig();

    config.setMaximumPoolSize(25);

    config.setPoolName("helper-sql-" + COUNTER.getAndIncrement());
    config.setDataSourceClassName("org.mariadb.jdbc.MySQLDataSource");
    config.addDataSourceProperty("serverName", credentials.getAddress());
    config.addDataSourceProperty("port", credentials.getPort());
    config.addDataSourceProperty("databaseName", credentials.getDatabase());
    config.setUsername(credentials.getUsername());
    config.setPassword(credentials.getPassword());

    // hack for the mariadb driver
    config.addDataSourceProperty("properties", "useUnicode=true;characterEncoding=utf8");

    // We will wait for 15 seconds to get a connection from the pool.
    // Default is 30, but it shouldn't be taking that long.
    config.setConnectionTimeout(TimeUnit.SECONDS.toMillis(15)); // 15000

    // If a connection is not returned within 10 seconds, it's probably safe to assume it's been leaked.
    config.setLeakDetectionThreshold(TimeUnit.SECONDS.toMillis(10)); // 10000

    hikari = new HikariDataSource(config);
}
 
開發者ID:lucko,項目名稱:helper,代碼行數:26,代碼來源:HikariWrapper.java

示例3: getDefaultHikariConfig

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
@Nonnull
public static HikariConfig getDefaultHikariConfig() {
    final HikariConfig hikariConfig = new HikariConfig();

    //more database connections don't help with performance, so use a default value based on available cores
    //http://www.dailymotion.com/video/x2s8uec_oltp-performance-concurrent-mid-tier-connections_tech
    hikariConfig.setMaximumPoolSize(Math.max(Runtime.getRuntime().availableProcessors(), 4));

    //timeout the validation query (will be done automatically through Connection.isValid())
    hikariConfig.setValidationTimeout(3000);
    hikariConfig.setConnectionTimeout(10000);
    hikariConfig.setAutoCommit(false);

    hikariConfig.setDriverClassName("org.postgresql.Driver");

    return hikariConfig;
}
 
開發者ID:napstr,項目名稱:SqlSauce,代碼行數:18,代碼來源:DatabaseConnection.java

示例4: setupPool

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
private void setupPool() {
    HikariConfig config = new HikariConfig();

    config.setJdbcUrl("jdbc:mysql://" + this.credentials.getHostname() + ":" + this.credentials.getPort() + "/" + this.credentials.getDatabaseName());
    config.setDriverClassName("com.mysql.jdbc.Driver");
    config.setUsername(this.credentials.getUsername());
    config.setPassword(this.credentials.getPassword());
    config.setMinimumIdle(this.minimumConnections);
    config.setMaximumPoolSize(this.maximumConnections);
    config.setConnectionTimeout(this.connectionTimeout);

    try {
        this.dataSource = new HikariDataSource(config);
    }
    catch (Exception e) {
        Bukkit.getLogger().severe("[ZorahPractice] - Unable to establish MySQL connection, plugin disabled.");
        Bukkit.getServer().getPluginManager().disablePlugin(PracticePlugin.getInstance());
    }
}
 
開發者ID:ijoeleoli,項目名稱:ZorahPractice,代碼行數:20,代碼來源:ConnectionPoolManager.java

示例5: enableDatabaseSQLiteTest

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
@Test
public void enableDatabaseSQLiteTest() {
    try {
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.sqlite.JDBC");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:sqlite:PetBlocks.db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assert.fail();
    }
}
 
開發者ID:Shynixn,項目名稱:PetBlocks,代碼行數:18,代碼來源:DatabaseIT.java

示例6: enableDatabaseMySQLTest

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
@Test
public void enableDatabaseMySQLTest() {
    try {
        final DB database = DB.newEmbeddedDB(3306);
        database.start();
        try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
            try (Statement statement = conn.createStatement()) {
                statement.executeUpdate("CREATE DATABASE db");
            }
        }
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
        database.stop();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assert.fail();
    }
}
 
開發者ID:Shynixn,項目名稱:PetBlocks,代碼行數:26,代碼來源:DatabaseIT.java

示例7: ExtensionHikariConnectionContext

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
/**
 * Initializes a new databaseConnectionContext for the given url, userName and password
 *
 * @param url      url
 * @param userName userNames
 * @param password password
 */
private ExtensionHikariConnectionContext(String driver, String url, String userName, String password, SQlRetriever retriever) {
    super();
    this.retriever = retriever;
    final HikariConfig config = new HikariConfig();
    config.setDriverClassName(driver);
    config.setConnectionTestQuery("SELECT 1");
    config.setJdbcUrl(url);
    if (userName != null)
        config.setUsername(userName);
    if (password != null)
        config.setPassword(password);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    if (driver.equals(SQLITE_DRIVER))
        config.setMaximumPoolSize(1);
    else
        config.setMaximumPoolSize(10);
    this.ds = new HikariDataSource(config);
    Logger.getLogger(this.getClass().getSimpleName()).log(Level.INFO, "Connected to " + url);
}
 
開發者ID:Shynixn,項目名稱:PetBlocks,代碼行數:29,代碼來源:ExtensionHikariConnectionContext.java

示例8: ExtensionHikariConnectionContext

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
/**
 * Initializes a new databaseConnectionContext for the given url, userName and password
 *
 * @param url      url
 * @param userName userName
 * @param password password
 */
private ExtensionHikariConnectionContext(String driver, String url, String userName, String password, SQlRetriever retriever) {
    super();
    this.retriever = retriever;
    final HikariConfig config = new HikariConfig();
    config.setDriverClassName(driver);
    config.setConnectionTestQuery("SELECT 1");
    config.setJdbcUrl(url);
    if (userName != null)
        config.setUsername(userName);
    if (password != null)
        config.setPassword(password);
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
    if (driver.equals(SQLITE_DRIVER))
        config.setMaximumPoolSize(1);
    else
        config.setMaximumPoolSize(10);
    this.ds = new HikariDataSource(config);
    Logger.getLogger(this.getClass().getSimpleName()).log(Level.INFO, "Connected to " + url);
}
 
開發者ID:Shynixn,項目名稱:BlockBall,代碼行數:29,代碼來源:ExtensionHikariConnectionContext.java

示例9: setUpClass

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
@BeforeClass
public static void setUpClass() throws ParserConfigurationException, IOException, SAXException, SQLException, LiquibaseException {
    ApplicationConfig config = ConfigurationBuilder.createBuilder().loadXMLConfiguration().getConfiguration();

    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl("jdbc:" + config.getDbUrl() + "/" + config.getDbName());
    hikariConfig.setUsername(config.getDbUser());
    hikariConfig.setPassword(config.getDbPassword());
    hikariConfig.setMaximumPoolSize(config.getThreadLimit());
    if(config.isDbIgnoreSSLWarn()) {
        hikariConfig.addDataSourceProperty("useSSL", false);
    }

    dataSource = new HikariDataSource(hikariConfig);

    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(dataSource.getConnection()));

    Liquibase liquibase = new Liquibase("db/changelog/db.changelog-master.yaml", new ClassLoaderResourceAccessor(), database);

    liquibase.update(new Contexts(), new LabelExpression());
}
 
開發者ID:XIVStats,項目名稱:XIVStats-Gatherer-Java,代碼行數:22,代碼來源:GathererControllerIT.java

示例10: getDataSourceFromConfig

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
public static HikariDataSource getDataSourceFromConfig(
    Config conf
    , MetricRegistry metricRegistry
    , HealthCheckRegistry healthCheckRegistry) {

    HikariConfig jdbcConfig = new HikariConfig();
    jdbcConfig.setPoolName(conf.getString("poolName"));
    jdbcConfig.setMaximumPoolSize(conf.getInt("maximumPoolSize"));
    jdbcConfig.setMinimumIdle(conf.getInt("minimumIdle"));
    jdbcConfig.setJdbcUrl(conf.getString("jdbcUrl"));
    jdbcConfig.setUsername(conf.getString("username"));
    jdbcConfig.setPassword(conf.getString("password"));

    jdbcConfig.addDataSourceProperty("cachePrepStmts", conf.getBoolean("cachePrepStmts"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSize", conf.getInt("prepStmtCacheSize"));
    jdbcConfig.addDataSourceProperty("prepStmtCacheSqlLimit", conf.getInt("prepStmtCacheSqlLimit"));
    jdbcConfig.addDataSourceProperty("useServerPrepStmts", conf.getBoolean("useServerPrepStmts"));

    // Add HealthCheck
    jdbcConfig.setHealthCheckRegistry(healthCheckRegistry);

    // Add Metrics
    jdbcConfig.setMetricRegistry(metricRegistry);
    return new HikariDataSource(jdbcConfig);
}
 
開發者ID:StubbornJava,項目名稱:StubbornJava,代碼行數:26,代碼來源:ConnectionPool.java

示例11: initConnection

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
private void initConnection() throws Exception {
	HikariConfig config = new HikariConfig();
	config.setPoolName("Parties");
	config.setJdbcUrl(Variables.storage_settings_mysql_url);
	config.setUsername(Variables.storage_settings_mysql_username);
	config.setPassword(Variables.storage_settings_mysql_password);
	config.setMaximumPoolSize(Variables.storage_settings_mysql_poolsize);
	config.setMinimumIdle(Variables.storage_settings_mysql_poolsize);
	config.setMaxLifetime(Variables.storage_settings_mysql_connlifetime);
	config.setIdleTimeout(Variables.storage_settings_mysql_conntimeout);
	
	// Properties: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html
	config.addDataSourceProperty("cachePreStmts", "true"); // Enable Prepared Statement caching
	config.addDataSourceProperty("prepStmtCacheSize", "25"); // How many PS cache, default: 25
	config.addDataSourceProperty("useServerPrepStmts", "true"); // If supported use PS server-side
	config.addDataSourceProperty("useLocalSessionState", "true"); // Enable setAutoCommit
	config.addDataSourceProperty("useLocalTransactionState", "true"); // Enable commit/rollbacks
	
	hikariDataSource = new HikariDataSource(config);
}
 
開發者ID:AlessioDP,項目名稱:Parties,代碼行數:21,代碼來源:MySQLData.java

示例12: provide

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
@Override
public DataSource provide() {
    LOGGER.debug("{}", this);
    HikariConfig config = new HikariConfig();
    config.setJdbcUrl(jdbcUrl);
    config.setUsername(username);
    config.setPassword(password);
    config.setAutoCommit(autoCommit);
    config.setMaximumPoolSize(maximumPoolSize);
    config.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
    config.addDataSourceProperty("cachePrepStmts", "true");
    config.addDataSourceProperty("prepStmtCacheSize", "250");
    config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");

    HikariDataSource dataSource = new HikariDataSource(config);
    LOGGER.debug("provide DataSource {}", dataSource);

    return dataSource;
}
 
開發者ID:protoxme,項目名稱:protox-webapp-archetype,代碼行數:20,代碼來源:DataSourceFactory.java

示例13: start

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
@Override
public void start() {
	HikariConfig config = new HikariConfig();
	config.setJdbcUrl(this.conURL);
	config.setUsername(this.username);
	config.setPassword(this.password);
	config.setDriverClassName(this.driverName);
	config.setMaximumPoolSize(max);
	config.setMinimumIdle(min);
	if (this.testSql != null && this.testSql.trim().length() > 0) {
		config.setConnectionTestQuery(testSql);
	}
	config.setPoolName("HikariCPPool[" + username + "]");
	config.addDataSourceProperty("cachePrepStmts", AppProperties.get("HikariCPPool_cachePrepStmts", "true"));
	config.addDataSourceProperty("prepStmtCacheSize", AppProperties.get("HikariCPPool_prepStmtCacheSize", "250"));
	config.addDataSourceProperty("prepStmtCacheSqlLimit",
			AppProperties.get("HikariCPPool_prepStmtCacheSqlLimit", "2048"));
	config.setConnectionTimeout(AppProperties.getAsInt("HikariCPPool_connectionTimeout", 30000));
	config.setIdleTimeout(AppProperties.getAsInt("HikariCPPool_idleTimeout", 600000));
	config.setMaxLifetime(AppProperties.getAsInt("HikariCPPool_maxLifetime", 1800000));
	// HikariDataSource ds = new HikariDataSource(config);
	// this.datasource=ds.getDataSource();
	this.datasource = new HikariDataSource(config);
}
 
開發者ID:jbeetle,項目名稱:BJAF3.x,代碼行數:25,代碼來源:HikariCPPool.java

示例14: getDataSource

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
@Bean
@Primary
public DataSource getDataSource() {
    HikariConfig config = new HikariConfig();
    config.setDriverClassName("com.mysql.jdbc.Driver");
    config.setJdbcUrl("jdbc:mysql://localhost:3306/test");
    config.setUsername("root");
    config.setPassword("root");
    config.setMaximumPoolSize(500);
    config.setMinimumIdle(10);
    return new HikariDataSource(config);
}
 
開發者ID:SkywalkingTest,項目名稱:Agent-Benchmarks,代碼行數:13,代碼來源:DataSourceConfiguration.java

示例15: build

import com.zaxxer.hikari.HikariConfig; //導入方法依賴的package包/類
@Override
public ManagedDataSource build(final MetricRegistry metricRegistry, final String name) {
    final Properties properties = new Properties();
    for (final Map.Entry<String, String> property : this.properties.entrySet()) {
        properties.setProperty(property.getKey(), property.getValue());
    }

    final HikariConfig config = new HikariConfig();
    config.setMetricRegistry(metricRegistry);
    if (healthCheckRegistry != null) {
        config.setHealthCheckRegistry(healthCheckRegistry);
    }

    config.setAutoCommit(autoCommit);
    config.setDataSourceProperties(properties);
    if (datasourceClassName != null) {
        config.setDataSourceClassName(datasourceClassName);
    } else {
        config.setDriverClassName(driverClass);
    }

    config.setMaximumPoolSize(maxSize);
    minSize.ifPresent(config::setMinimumIdle);
    config.setPoolName(name);
    config.setUsername(user);
    config.setPassword(user != null && password == null ? "" : password);
    return new HikariManagedPooledDataSource(config);
}
 
開發者ID:nickbabcock,項目名稱:dropwizard-hikaricp-benchmark,代碼行數:29,代碼來源:HikariDataSourceFactory.java


注:本文中的com.zaxxer.hikari.HikariConfig.setMaximumPoolSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。