diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index c7a41a1f0dce2..93109dfd8abd7 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -117,10 +117,9 @@ public final List getConnections(final String dataSourceName, final return result; } - @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") - private synchronized List createConnections(final DataSource dataSource, final int connectionSize) throws SQLException { + private List createConnections(final DataSource dataSource, final int connectionSize) throws SQLException { List result = new ArrayList<>(connectionSize); - synchronized (dataSource) { + synchronized (getDataSourceMap()) { for (int i = 0; i < connectionSize; i++) { Connection connection = dataSource.getConnection(); replayMethodsInvocation(connection); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCBackendDataSource.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCBackendDataSource.java index 90713029a915b..a20fcdb85e785 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCBackendDataSource.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCBackendDataSource.java @@ -104,13 +104,11 @@ public Connection getConnection(final String dataSourceName) throws SQLException * @return connections * @throws SQLException SQL exception */ - @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") public List getConnections(final String dataSourceName, final int connectionSize) throws SQLException { List result = new ArrayList<>(connectionSize); - DataSource dataSource = getDataSourceMap().get(dataSourceName); - synchronized (dataSource) { + synchronized (getDataSourceMap()) { for (int i = 0; i < connectionSize; i++) { - result.add(dataSource.getConnection()); + result.add(getDataSourceMap().get(dataSourceName).getConnection()); } } return result;