From cc9ebffc57e6343745cb1eadc47360d6107936bc Mon Sep 17 00:00:00 2001 From: xpc <1821349743@qq.com> Date: 星期二, 30 一月 2024 19:04:26 +0800 Subject: [PATCH] commit --- product-server-datasource/src/main/java/com/product/datasource/connection/ConnectionManager.java | 78 ++++++++++++++++++++------------------- 1 files changed, 40 insertions(+), 38 deletions(-) diff --git a/product-server-datasource/src/main/java/com/product/datasource/connection/ConnectionManager.java b/product-server-datasource/src/main/java/com/product/datasource/connection/ConnectionManager.java index df184b5..a97e68f 100644 --- a/product-server-datasource/src/main/java/com/product/datasource/connection/ConnectionManager.java +++ b/product-server-datasource/src/main/java/com/product/datasource/connection/ConnectionManager.java @@ -200,46 +200,48 @@ } Boolean enabling = Global.getPropertyToBoolean("data.system.oracle.connection-pool.enabling", "false"); if (enabling) { - DruidDataSource druidDataSource = DB_DRUID_DATA_SOURCE_MAP.get(ArrayUtil.join(params, ",")); - if (druidDataSource == null || druidDataSource.isClosed()) { - druidDataSource = new DruidDataSource(); - druidDataSource.setUrl(url); - druidDataSource.setUsername(dbe.getUserName()); - druidDataSource.setPassword(dbe.getPassWord()); - // 鍒濆鍖栨椂寤虹珛鐗╃悊杩炴帴鐨勪釜鏁� - druidDataSource.setInitialSize(getProperty("data.system.oracle.connection-pool.initial-size", 10)); - // 鏈�澶ф椿鍔ㄨ繛鎺ユ暟 - druidDataSource.setMaxActive(getProperty("data.system.oracle.connection-pool.max-active", 100)); - // 鏈�灏忕┖闂茶繛鎺ユ暟 - druidDataSource.setMinIdle(getProperty("data.system.oracle.connection-pool.min-idle", 20)); - // 鏍¢獙鏌ヨ璇彞 - druidDataSource.setValidationQuery(dbe.getDataBaseType().getValidationQuery()); - // 褰撹繛鎺ョ┖闂叉椂鏄惁娴嬭瘯杩炴帴鏈夋晥鎬� - druidDataSource.setTestWhileIdle(true); - // 涓ゆ绌洪棽杩炴帴娓呴櫎涔嬮棿鐨勬椂闂撮棿闅� - druidDataSource.setTimeBetweenEvictionRunsMillis(60000); - druidDataSource.setMaxWait(60 * 1000); - druidDataSource.setPoolPreparedStatements(true); - druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(100); - druidDataSource.setRemoveAbandoned(true); - //鍗婂皬鏃跺己鍒跺綊杩樿繛鎺� - druidDataSource.setRemoveAbandonedTimeout(60 * 30); - DB_DRUID_DATA_SOURCE_MAP.put(ArrayUtil.join(params, ","), druidDataSource); - try { - //鑾疯幏鍙栬繛鎺� - Connection connection = druidDataSource.getConnection(); - //娴嬭瘯杩炴帴 - if (!connectionValidity(connection, dbe.getDataBaseType())) { + synchronized (url.intern()){ + DruidDataSource druidDataSource = DB_DRUID_DATA_SOURCE_MAP.get(ArrayUtil.join(params, ",")); + if (druidDataSource == null || druidDataSource.isClosed()) { + druidDataSource = new DruidDataSource(); + druidDataSource.setUrl(url); + druidDataSource.setUsername(dbe.getUserName()); + druidDataSource.setPassword(dbe.getPassWord()); + // 鍒濆鍖栨椂寤虹珛鐗╃悊杩炴帴鐨勪釜鏁� + druidDataSource.setInitialSize(getProperty("data.system.oracle.connection-pool.initial-size", 10)); + // 鏈�澶ф椿鍔ㄨ繛鎺ユ暟 + druidDataSource.setMaxActive(getProperty("data.system.oracle.connection-pool.max-active", 100)); + // 鏈�灏忕┖闂茶繛鎺ユ暟 + druidDataSource.setMinIdle(getProperty("data.system.oracle.connection-pool.min-idle", 20)); + // 鏍¢獙鏌ヨ璇彞 + druidDataSource.setValidationQuery(dbe.getDataBaseType().getValidationQuery()); + // 褰撹繛鎺ョ┖闂叉椂鏄惁娴嬭瘯杩炴帴鏈夋晥鎬� + druidDataSource.setTestWhileIdle(true); + // 涓ゆ绌洪棽杩炴帴娓呴櫎涔嬮棿鐨勬椂闂撮棿闅� + druidDataSource.setTimeBetweenEvictionRunsMillis(60000); + druidDataSource.setMaxWait(60 * 1000); + druidDataSource.setPoolPreparedStatements(true); + druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(100); + druidDataSource.setRemoveAbandoned(true); + //鍗婂皬鏃跺己鍒跺綊杩樿繛鎺� + druidDataSource.setRemoveAbandonedTimeout(60 * 30); + DB_DRUID_DATA_SOURCE_MAP.put(ArrayUtil.join(params, ","), druidDataSource); + try { + //鑾疯幏鍙栬繛鎺� + Connection connection = druidDataSource.getConnection(); + //娴嬭瘯杩炴帴 + if (!connectionValidity(connection, dbe.getDataBaseType())) { + throw new BaseException(ErrorCode.GET_CONNECTION_FAIL); + } + return connection; + } catch (BaseException e) { + throw e; + } catch (Exception e) { + e.printStackTrace(); + log.error("鑾峰彇閾炬帴澶辫触", e); + log.error(url); throw new BaseException(ErrorCode.GET_CONNECTION_FAIL); } - return connection; - } catch (BaseException e) { - throw e; - } catch (Exception e) { - e.printStackTrace(); - log.error("鑾峰彇閾炬帴澶辫触", e); - log.error(url); - throw new BaseException(ErrorCode.GET_CONNECTION_FAIL); } } } -- Gitblit v1.9.2