Skip to content

Commit

Permalink
for #1205, sync SQLExecutePrepareTemplate for Get connection sync to …
Browse files Browse the repository at this point in the history
…prevent dead lock
  • Loading branch information
terrymanu committed Sep 19, 2018
1 parent 0559861 commit 58f684d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public final class SQLExecutePrepareTemplate {
public Collection<ShardingExecuteGroup<StatementExecuteUnit>> getExecuteUnitGroups(final Collection<RouteUnit> routeUnits, final SQLExecutePrepareCallback callback) throws SQLException {
Map<String, List<SQLUnit>> sqlUnitGroups = getSQLUnitGroups(routeUnits);
Collection<ShardingExecuteGroup<StatementExecuteUnit>> result = new LinkedList<>();
for (Entry<String, List<SQLUnit>> entry : sqlUnitGroups.entrySet()) {
result.addAll(getSQLExecuteGroups(entry.getKey(), entry.getValue(), callback));
synchronized (SQLExecutePrepareTemplate.class) {
for (Entry<String, List<SQLUnit>> entry : sqlUnitGroups.entrySet()) {
result.addAll(getSQLExecuteGroups(entry.getKey(), entry.getValue(), callback));
}
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,10 @@ public final List<Connection> getConnections(final String dataSourceName, final

private List<Connection> createConnections(final DataSource dataSource, final int connectionSize) throws SQLException {
List<Connection> result = new ArrayList<>(connectionSize);
synchronized (getDataSourceMap()) {
for (int i = 0; i < connectionSize; i++) {
Connection connection = dataSource.getConnection();
replayMethodsInvocation(connection);
result.add(connection);
}
for (int i = 0; i < connectionSize; i++) {
Connection connection = dataSource.getConnection();
replayMethodsInvocation(connection);
result.add(connection);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ public Connection getConnection(final String dataSourceName) throws SQLException
*/
public List<Connection> getConnections(final String dataSourceName, final int connectionSize) throws SQLException {
List<Connection> result = new ArrayList<>(connectionSize);
synchronized (getDataSourceMap()) {
for (int i = 0; i < connectionSize; i++) {
result.add(getDataSourceMap().get(dataSourceName).getConnection());
}
for (int i = 0; i < connectionSize; i++) {
result.add(getDataSourceMap().get(dataSourceName).getConnection());
}
return result;
}
Expand Down

0 comments on commit 58f684d

Please sign in to comment.