Skip to content

Commit

Permalink
for #1205, sync data source map for Get connection sync to prevent de…
Browse files Browse the repository at this point in the history
…ad lock
  • Loading branch information
terrymanu committed Sep 19, 2018
1 parent 23db595 commit 874e9ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ public final List<Connection> getConnections(final String dataSourceName, final
return result;
}

@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
private synchronized List<Connection> createConnections(final DataSource dataSource, final int connectionSize) throws SQLException {
private List<Connection> createConnections(final DataSource dataSource, final int connectionSize) throws SQLException {
List<Connection> result = new ArrayList<>(connectionSize);
synchronized (dataSource) {
synchronized (getDataSourceMap()) {
for (int i = 0; i < connectionSize; i++) {
Connection connection = dataSource.getConnection();
replayMethodsInvocation(connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,11 @@ 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);
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;
Expand Down

0 comments on commit 874e9ab

Please sign in to comment.