fixed concurrency problem uncovered during JMH-based throughput testing (Act 3)

This commit is contained in:
Steve Ebersole 2019-11-21 20:56:48 -06:00
parent 1b2aa85fa7
commit 2b65c73fb7
1 changed files with 8 additions and 4 deletions

View File

@ -181,10 +181,14 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
// The other option would be to leverage `java.util.concurrent.locks.ReadWriteLock`
// to protect access. However, synchronized is much simpler here. We will verify
// during throughput testing whether this is an issue and consider changes then
if ( cacheableSqmInterpretation == null ) {
CacheableSqmInterpretation localCopy = cacheableSqmInterpretation;
if ( localCopy == null ) {
synchronized ( this ) {
if ( cacheableSqmInterpretation == null ) {
cacheableSqmInterpretation = buildCacheableSqmInterpretation(
localCopy = cacheableSqmInterpretation;
if ( localCopy == null ) {
cacheableSqmInterpretation = localCopy = buildCacheableSqmInterpretation(
sqm,
domainParameterXref,
executionContext
@ -193,7 +197,7 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
}
}
return cacheableSqmInterpretation;
return localCopy;
}
private static CacheableSqmInterpretation buildCacheableSqmInterpretation(