Skip to content

Commit

Permalink
for #1205, remove sync for SQLExecutePrepareTemplate and recover sync…
Browse files Browse the repository at this point in the history
… for get connections on same data source, because data source map always use same hash sequence to iterator entries
  • Loading branch information
terrymanu committed Sep 20, 2018
1 parent c9e5b5e commit 1f7c0be
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ 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<>();
synchronized (SQLExecutePrepareTemplate.class) {
for (Entry<String, List<SQLUnit>> entry : sqlUnitGroups.entrySet()) {
result.addAll(getSQLExecuteGroups(entry.getKey(), entry.getValue(), callback));
}
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 @@ -117,12 +117,15 @@ public final List<Connection> getConnections(final String dataSourceName, final
return result;
}

@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private List<Connection> createConnections(final DataSource dataSource, final int connectionSize) throws SQLException {
List<Connection> result = new ArrayList<>(connectionSize);
for (int i = 0; i < connectionSize; i++) {
Connection connection = dataSource.getConnection();
replayMethodsInvocation(connection);
result.add(connection);
synchronized (dataSource) {
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 @@ -104,10 +104,14 @@ public Connection getConnection(final String dataSourceName) throws SQLException
* @return connections
* @throws SQLException SQL exception
*/
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
public List<Connection> getConnections(final String dataSourceName, final int connectionSize) throws SQLException {
List<Connection> result = new ArrayList<>(connectionSize);
for (int i = 0; i < connectionSize; i++) {
result.add(getDataSourceMap().get(dataSourceName).getConnection());
DataSource dataSource = getDataSourceMap().get(dataSourceName);
synchronized (dataSource) {
for (int i = 0; i < connectionSize; i++) {
result.add(dataSource.getConnection());
}
}
return result;
}
Expand Down

0 comments on commit 1f7c0be

Please sign in to comment.