|
@@ -18,6 +18,7 @@ package org.hsweb.web.datasource.dynamic;
|
|
|
|
|
|
import com.atomikos.jdbc.AtomikosDataSourceBean;
|
|
|
import com.atomikos.jdbc.AtomikosSQLException;
|
|
|
+import org.hsweb.commons.StringUtils;
|
|
|
import org.hsweb.concurrent.lock.LockFactory;
|
|
|
import org.hsweb.web.bean.po.datasource.DataSource;
|
|
|
import org.hsweb.web.core.datasource.DatabaseType;
|
|
@@ -139,6 +140,8 @@ public class DynamicDataSourceServiceImpl implements DynamicDataSourceService {
|
|
|
properties.setType(DatabaseType.fromJdbcUrl(dataSource.getUrl()));
|
|
|
properties.setTestQuery(dataSource.getTestSql());
|
|
|
Map<String, Object> otherProperties = dataSource.getProperties();
|
|
|
+ int initTimeout = StringUtils.toInt(otherProperties.getOrDefault("initTimeOut", 30 * 1000));
|
|
|
+ otherProperties.remove("initTimeOut");
|
|
|
try {
|
|
|
properties.afterPropertiesSet();
|
|
|
} catch (Exception e) {
|
|
@@ -167,11 +170,14 @@ public class DynamicDataSourceServiceImpl implements DynamicDataSourceService {
|
|
|
//初始化检测
|
|
|
new Thread(() -> {
|
|
|
try {
|
|
|
- Thread.sleep(30 * 1000);
|
|
|
+ Thread.sleep(initTimeout);
|
|
|
if (!success[0]) {
|
|
|
logger.error("初始化jdbc超时:{}", dataSourceBean);
|
|
|
- closeDataSource(dataSourceBean);
|
|
|
- cache.remove(dataSource.getId());
|
|
|
+ try {
|
|
|
+ closeDataSource(dataSourceBean);
|
|
|
+ } finally {
|
|
|
+ cache.remove(dataSource.getId());
|
|
|
+ }
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
|