本文整理汇总了Java中com.zaxxer.hikari.HikariConfig.setConnectionTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java HikariConfig.setConnectionTimeout方法的具体用法?Java HikariConfig.setConnectionTimeout怎么用?Java HikariConfig.setConnectionTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.zaxxer.hikari.HikariConfig
的用法示例。
在下文中一共展示了HikariConfig.setConnectionTimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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());
}
}
示例4: dataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
public DataSource dataSource() {
HikariConfig dataSourceConfig = new HikariConfig();
dataSourceConfig.setDriverClassName(environment.getRequiredProperty("spring.datasource.driver-class-name"));
dataSourceConfig.setJdbcUrl(environment.getRequiredProperty("spring.datasource.url"));
dataSourceConfig.setUsername(environment.getRequiredProperty("spring.datasource.username"));
dataSourceConfig.setPassword(environment.getRequiredProperty("spring.datasource.password"));
dataSourceConfig.setMaximumPoolSize(Integer.parseInt(environment.getRequiredProperty("spring.datasource.maximumPoolSize")));
dataSourceConfig.setMinimumIdle(Integer.parseInt(environment.getRequiredProperty("spring.datasource.minimumIdle")));
dataSourceConfig.setMaxLifetime(Integer.parseInt(environment.getRequiredProperty("spring.datasource.maxLifetime")));
dataSourceConfig.setConnectionTimeout(Long.parseLong(environment.getRequiredProperty("spring.datasource.connectionTimeout")));
dataSourceConfig.setIdleTimeout(Long.parseLong(environment.getRequiredProperty("spring.datasource.idleTimeout")));
dataSourceConfig.addDataSourceProperty("poolName", environment.getRequiredProperty("spring.datasource.poolName"));
dataSourceConfig.addDataSourceProperty("cachePrepStmts", "true");
dataSourceConfig.addDataSourceProperty("prepStmtCacheSize", "250");
dataSourceConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
return new HikariDataSource(dataSourceConfig);
}
示例5: dataSource
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean
public DataSource dataSource() {
HikariConfig configuration = new HikariConfig();
configuration.setJdbcUrl(url);
configuration.setUsername(username);
configuration.setPassword(password);
configuration.setAutoCommit(false);
configuration.setMaximumPoolSize(maxPoolSize);
configuration.setConnectionTimeout(connectionTimeout);
configuration.setMaxLifetime(maxLifetime);
Properties properties = new Properties();
properties.setProperty("cachePrepStmts", cachePrepStmts);
properties.setProperty("prepStmtCacheSize", prepStmtCacheSize);
properties.setProperty("prepStmtCacheSqlLimit", prepStmtCacheSqlLimit);
properties.setProperty("useServerPrepStmts", useServerPrepStmts);
configuration.setDataSourceProperties(properties);
configuration.setConnectionInitSql("SET NAMES " + connectionCharacter);
return new HikariDataSource(configuration);
}
示例6: initDatabase
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public void initDatabase() {
LOGGER.debug("Connecting to database");
HikariConfig databaseConfig = new HikariConfig();
String driverType = config.get("driverType");
String host = config.get("host");
String port = config.get("port");
String database = config.get("database");
String jdbcUrl = "jdbc:" + driverType + "://" + host + ':' + port + '/' + database;
databaseConfig.setJdbcUrl(jdbcUrl);
databaseConfig.setUsername("root");
databaseConfig.setPassword(config.get("password"));
databaseConfig.setConnectionTimeout(Long.parseLong(config.get("connectionTimeout")));
dataSource = new HikariDataSource(databaseConfig);
}
示例7: HikariCpImpl
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public HikariCpImpl() {
Properties properties = new Properties();
properties.setProperty("dataSourceClassName", "com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
properties.setProperty("dataSource.serverName", "127.0.0.1");
properties.setProperty("dataSource.portNumber", "3306");
properties.setProperty("dataSource.databaseName", "study");
properties.setProperty("dataSource.user", "root");
properties.setProperty("dataSource.password", "zhilaiadmin");
properties.setProperty("dataSource.encoding", "UTF-8");
properties.setProperty("maximumPoolSize", "100");
HikariConfig config = new HikariConfig(properties);
config.setConnectionTimeout(30 * 1000);
config.setIdleTimeout(60 * 1000);
config.setMaxLifetime(60 * 1000);
config.setMinimumIdle(50);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "1000");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
ds = new HikariDataSource(config);
}
示例8: 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);
}
示例9: Database
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public Database(Logger log, String user, String pass, String host, int port, String db,
int poolSize, long connectionTimeout, long idleTimeout, long maxLife) {
if(user != null && host != null && port > 0 && db != null) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + db);
config.setConnectionTimeout(connectionTimeout);
config.setIdleTimeout(idleTimeout);
config.setMaxLifetime(maxLife);
config.setMaximumPoolSize(poolSize);
config.setUsername(user);
if(pass != null) {
config.setPassword(pass);
}
datasource = new HikariDataSource(config);
try {
Connection conn = getConnection();
PreparedStatement statement = conn.prepareStatement(INIT_DATABASE);
statement.execute();
statement.close();
conn.close();
} catch (SQLException e) {
log.log(Level.SEVERE, "Unable to initialize database", e);
datasource = null;
}
} else {
datasource = null;
log.log(Level.SEVERE, "Database not configured and is unavailable");
}
}
示例10: doBenchHikari
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private void doBenchHikari() throws Exception {
HikariConfig config = new HikariConfig();
config.setDataSource(new StubDataSource());
config.setUsername("brettw");
config.setPassword("");
config.setMinimumIdle(0);
config.setMaximumPoolSize(32);
config.setConnectionTimeout(8000);
config.setAutoCommit(false);
DataSource ds = new HikariDataSource(config);
doBench(ds);
((AutoCloseable) ds).close();
}
示例11: get
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
@Override
public DataSource get() throws SQLException {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(baseConfig.getJdbcUrl());
config.setUsername(baseConfig.getUsername());
config.setPassword(baseConfig.getPassword());
config.setMinimumIdle(baseConfig.getMinimumIdle());
config.setMaximumPoolSize(baseConfig.getMaximumPoolSize());
config.setConnectionTestQuery(baseConfig.getConnectionTestQuery());
config.setIdleTimeout(baseConfig.getIdleTimeout());
config.setConnectionTimeout(baseConfig.getConnectionTimeout());
return new HikariDataSource(config);
}
示例12: getHikariConfig
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private HikariConfig getHikariConfig(AgroalDataSourceConfiguration dataSourceConfiguration) {
if ( dataSourceConfiguration.isXA() ) {
throw new UnsupportedOperationException( "Unsupported. Hikari does not support XA" );
}
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDataSourceJNDI( dataSourceConfiguration.jndiName() );
hikariConfig.setLeakDetectionThreshold( poolConfiguration.leakTimeout().toMillis() );
hikariConfig.setIdleTimeout( poolConfiguration.reapTimeout().toMillis() );
hikariConfig.setValidationTimeout( poolConfiguration.validationTimeout().toMillis() );
if ( factoryConfiguration.jdbcTransactionIsolation().isDefined() ) {
hikariConfig.setTransactionIsolation( "TRANSACTION_" + factoryConfiguration.jdbcTransactionIsolation().name() );
}
hikariConfig.setJdbcUrl( factoryConfiguration.jdbcUrl() );
hikariConfig.setAutoCommit( factoryConfiguration.autoCommit() );
hikariConfig.setConnectionInitSql( factoryConfiguration.initialSql() );
Principal principal = factoryConfiguration.principal();
if ( principal != null ) {
hikariConfig.setUsername( factoryConfiguration.principal().getName() );
}
for ( Object credential : factoryConfiguration.credentials() ) {
if ( credential instanceof SimplePassword ) {
hikariConfig.setPassword( ( (SimplePassword) credential ).getWord() );
}
}
hikariConfig.setMaximumPoolSize( poolConfiguration.maxSize() );
hikariConfig.setConnectionTimeout( poolConfiguration.acquisitionTimeout().toMillis() );
hikariConfig.setDriverClassName( factoryConfiguration.driverClassName() );
return hikariConfig;
}
示例13: create
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public static HikariDataSource create(String dbName) {
String dbUrl = String.format(CONNECTION_STR_PATTERN, H2DataBaseServer.HOST, H2DataBaseServer.PORT, dbName);
HikariConfig config = new HikariConfig();
config.setDriverClassName(DRIVER_NAME);
config.setJdbcUrl(dbUrl);
config.setUsername("");
config.setPassword("");
config.setConnectionTimeout(CONNECTION_TIMEOUT);
config.setMaximumPoolSize(MAX_POOL_SIZE);
return new HikariDataSource(config);
}
示例14: setupPool
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
private void setupPool() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database);
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setUsername(username);
config.setPassword(password);
config.setMinimumIdle(minimumIdle);
config.setMaximumPoolSize(poolSize);
config.setConnectionTimeout(connectionTimeout);
config.setConnectionTestQuery(testQuery);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
dataSource = new HikariDataSource(config);
}
示例15: HikariCPComponent
import com.zaxxer.hikari.HikariConfig; //导入方法依赖的package包/类
public HikariCPComponent(OptionMap options) {
config = new HikariConfig();
if (options.containsKey("uri")) config.setJdbcUrl(options.getString("uri"));
if (options.containsKey("username")) config.setUsername(options.getString("username"));
if (options.containsKey("password")) config.setPassword(options.getString("password"));
if (options.containsKey("autoCommit?")) config.setAutoCommit(options.getBoolean("autoCommit?"));
if (options.containsKey("connTimeout")) config.setConnectionTimeout(options.getLong("connTimeout"));
if (options.containsKey("idleTimeout")) config.setIdleTimeout(options.getLong("idleTimeout"));
if (options.containsKey("maxLifetime")) config.setMaxLifetime(options.getLong("maxLifetime"));
if (options.containsKey("maxPoolSize")) config.setMaximumPoolSize(options.getInt("maxPoolSize"));
if (options.containsKey("minIdle")) config.setMinimumIdle(options.getInt("minIdle"));
if (options.containsKey("poolName")) config.setPoolName(options.getString("uri"));
}