本文整理汇总了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();
}
示例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);
}
示例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;
}
示例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());
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}