本文整理汇总了Java中com.mchange.v2.c3p0.ComboPooledDataSource.setUnreturnedConnectionTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java ComboPooledDataSource.setUnreturnedConnectionTimeout方法的具体用法?Java ComboPooledDataSource.setUnreturnedConnectionTimeout怎么用?Java ComboPooledDataSource.setUnreturnedConnectionTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mchange.v2.c3p0.ComboPooledDataSource
的用法示例。
在下文中一共展示了ComboPooledDataSource.setUnreturnedConnectionTimeout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAdminDataSource
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
/**
*
*
*/
public boolean createAdminDataSource() throws Exception {
String dbHost = "", dbUser = "", dbPass = "", dbPort = "", url = "";
try {
dbHost = this.config.getProp(MAIN_CONFIG, MASTER_DBHOST);
dbUser = this.config.getProp(MAIN_CONFIG, MASTER_DBUSER);
dbPass = this.config.getProp(MAIN_CONFIG, MASTER_DBPASS);
dbPort = this.config.getProp(MAIN_CONFIG, MASTER_DBPORT);
url = url + URL_PREFIX + dbHost + ":" + dbPort + "?" + DRIVER_PARAMETERS;
newAdminDataSource = new ComboPooledDataSource();
newAdminDataSource.setDriverClass(DRIVER); // loads the mariadb-jdbc driver
newAdminDataSource.setJdbcUrl(url);
newAdminDataSource.setUser(dbUser);
if (dbPass != null && !dbPass.isEmpty()) {
newAdminDataSource.setPassword(dbPass);
}
// the settings below are optional -- c3p0 can work with defaults
newAdminDataSource.setMinPoolSize(0);
newAdminDataSource.setInitialPoolSize(0);
newAdminDataSource.setAcquireIncrement(5);
newAdminDataSource.setMaxPoolSize(20);
newAdminDataSource.setMaxIdleTimeExcessConnections(80);
newAdminDataSource.setMaxIdleTime(120);
newAdminDataSource.setUnreturnedConnectionTimeout(160);
} catch (Exception e) {
LOGGER.error("CAN NOT CREATE ADMIN DATA SOURCE", e);
}
return true;
}
示例2: openConnection
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
private void openConnection() {
try {
if (connectionView.getAddress().isEmpty()) {
showDialog("Server address required",
"Please specify an address");
return;
}
if (connectionView.getUsername().isEmpty()) {
showDialog("Username required", "Please specify a username");
return;
}
DriverManager.setLoginTimeout(5);
final String url = "jdbc:" + connectionTypeName + "://"
+ connectionView.getAddress() + "/"
+ connectionView.getDatabase();
ComboPooledDataSource source = new ComboPooledDataSource();
source.setDriverClass("com.mysql.jdbc.Driver");
source.setJdbcUrl(url);
source.setUser(connectionView.getUsername());
source.setPassword(connectionView.getPassword());
source.setUnreturnedConnectionTimeout(60);
source.setDebugUnreturnedConnectionStackTraces(true);
this.source = source;
switchToDataSetSelection();
} catch (Throwable ex) {
MonologFX dialog = new MonologFX(MonologFX.Type.ERROR);
dialog.setTitle("Could not connect to database");
dialog.setMessage(ex.getMessage()
+ "\nPlease ensure that the address, username, password, and database are correct.");
dialog.showDialog();
ex.printStackTrace();
}
}
示例3: createDataPool
import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
protected DataSource createDataPool(PoolConfig conf) {
if (!conf.isValid()) {
throw new RuntimeException("数据库驱动为空或者数据库用户名或者密码或者连接字符串为空");
}
log.info("db config:{}", conf.toString());
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setJdbcUrl(conf.jdbcUrl);
cpds.setUser(conf.userName);
cpds.setPassword(conf.password);
try {
cpds.setDriverClass(conf.driverClass);
} catch (PropertyVetoException e) {
throw new RuntimeException("数据库驱动设置失败");
}
cpds.setPreferredTestQuery("select 1");
cpds.setIdleConnectionTestPeriod(60);
if (conf.initialPoolSize != null && !conf.initialPoolSize.isEmpty()) {
cpds.setInitialPoolSize(Integer.parseInt(conf.initialPoolSize));
}
if (conf.acquireIncrement != null && !conf.acquireIncrement.isEmpty()) {
cpds.setAcquireIncrement(Integer.parseInt(conf.acquireIncrement));
}
if (conf.maxPoolSize != null && !conf.maxPoolSize.isEmpty()) {
cpds.setMaxPoolSize(Integer.parseInt(conf.maxPoolSize));
}
if (conf.minPoolSize != null && !conf.minPoolSize.isEmpty()) {
cpds.setMinPoolSize(Integer.parseInt(conf.minPoolSize));
}
if (conf.checkoutTimeout != null && !conf.checkoutTimeout.isEmpty()) {
cpds.setCheckoutTimeout(Integer.parseInt(conf.checkoutTimeout));
}
if (conf.maxStatements != null && !conf.maxStatements.isEmpty()) {
cpds.setMaxStatements(Integer.parseInt(conf.maxStatements));
}
if (conf.maxStatementsPerConnection != null && !conf.maxStatementsPerConnection.isEmpty()) {
cpds.setMaxStatementsPerConnection(Integer.parseInt(conf.maxStatementsPerConnection));
}
if (conf.maxIdleTime != null && !conf.maxIdleTime.isEmpty()) {
cpds.setMaxIdleTime(Integer.parseInt(conf.maxIdleTime));
}
if (conf.unreturnedConnectionTimeout != null && !conf.unreturnedConnectionTimeout.isEmpty()) {
cpds.setDebugUnreturnedConnectionStackTraces(true);
cpds.setUnreturnedConnectionTimeout(Integer.parseInt(conf.unreturnedConnectionTimeout));
} else {
cpds.setDebugUnreturnedConnectionStackTraces(false);
}
return cpds;
}