本文整理匯總了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;
}