Skip to content

Commit 8ca2634

Browse files
committed
Replace synchronized block with ReentrantLock.
Closes #3505
1 parent 0024985 commit 8ca2634

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/PartTreeJpaQuery.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import jakarta.persistence.criteria.CriteriaQuery;
2424

2525
import java.util.List;
26+
import java.util.concurrent.locks.ReentrantLock;
2627

2728
import org.springframework.data.domain.KeysetScrollPosition;
2829
import org.springframework.data.domain.OffsetScrollPosition;
@@ -208,6 +209,7 @@ private static boolean expectsCollection(Type type) {
208209
private class QueryPreparer {
209210

210211
private final @Nullable CriteriaQuery<?> cachedCriteriaQuery;
212+
private final ReentrantLock lock = new ReentrantLock();
211213
private final @Nullable ParameterBinder cachedParameterBinder;
212214
private final QueryParameterSetter.QueryMetadataCache metadataCache = new QueryParameterSetter.QueryMetadataCache();
213215

@@ -297,8 +299,11 @@ private Query restrictMaxResultsIfNecessary(Query query, @Nullable ScrollPositio
297299
private TypedQuery<?> createQuery(CriteriaQuery<?> criteriaQuery) {
298300

299301
if (this.cachedCriteriaQuery != null) {
300-
synchronized (this.cachedCriteriaQuery) {
302+
lock.lock();
303+
try {
301304
return getEntityManager().createQuery(criteriaQuery);
305+
} finally {
306+
lock.unlock();
302307
}
303308
}
304309

0 commit comments

Comments
 (0)