|
|
@ -26,18 +26,21 @@ public class JdbcServiceImpl implements JdbcService {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 所有数据源的连接池存在map里
|
|
|
|
* 所有数据源的连接池存在map里
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static Map<Long, DruidDataSource> map = new ConcurrentHashMap<>();
|
|
|
|
private Map<Long, DruidDataSource> map = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
private Object lock = new Object();
|
|
|
|
|
|
|
|
|
|
|
|
public DruidDataSource getJdbcConnectionPool(DataSourceDto dataSource) {
|
|
|
|
public DruidDataSource getJdbcConnectionPool(DataSourceDto dataSource) {
|
|
|
|
if (map.containsKey(dataSource.getId())) {
|
|
|
|
if (map.containsKey(dataSource.getId())) {
|
|
|
|
return map.get(dataSource.getId());
|
|
|
|
return map.get(dataSource.getId());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (!map.containsKey(dataSource.getId())) {
|
|
|
|
synchronized (lock) {
|
|
|
|
DruidDataSource pool = druidProperties.dataSource(dataSource.getJdbcUrl(),
|
|
|
|
if (!map.containsKey(dataSource.getId())) {
|
|
|
|
dataSource.getUsername(), dataSource.getPassword(), dataSource.getDriverName());
|
|
|
|
DruidDataSource pool = druidProperties.dataSource(dataSource.getJdbcUrl(),
|
|
|
|
map.put(dataSource.getId(), pool);
|
|
|
|
dataSource.getUsername(), dataSource.getPassword(), dataSource.getDriverName());
|
|
|
|
log.info("创建连接池成功:{}", dataSource.getJdbcUrl());
|
|
|
|
map.put(dataSource.getId(), pool);
|
|
|
|
|
|
|
|
log.info("创建连接池成功:{}", dataSource.getJdbcUrl());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return map.get(dataSource.getId());
|
|
|
|
return map.get(dataSource.getId());
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|