[
https://issues.apache.org/jira/browse/GROOVY-12371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18112045#comment-18112045
]
ASF GitHub Bot commented on GROOVY-12371:
-----------------------------------------
daniellansun commented on code in PR #2895:
URL: https://github.com/apache/groovy/pull/2895#discussion_r3943648072
##########
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java:
##########
@@ -5057,8 +5111,18 @@ private Statement
getAbstractStatement(AbstractStatementCommand cmd, Connection
if (cacheStatements) {
stmt = statementCache.get(sql);
if (stmt == null) {
- stmt = cmd.execute(connection, sql);
- statementCache.put(sql, stmt);
+ Statement created = cmd.execute(connection, sql);
+ synchronized (statementCache) {
+ Statement raced = statementCache.get(sql);
Review Comment:
Why not get and check the `raced` outside of `syncronized` block first and
use double-checked locking to avoid the statement with the same SQL is created
repeatedly.
> SQL: bound the statement cache and make it thread-safe
> ------------------------------------------------------
>
> Key: GROOVY-12371
> URL: https://issues.apache.org/jira/browse/GROOVY-12371
> Project: Groovy
> Issue Type: Task
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)