diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java index 714d691e91..facd80b288 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,7 +75,8 @@ import org.springframework.util.ConcurrentReferenceHashMap; */ public abstract class ExtendedEntityManagerCreator { - private static final Map, Class[]> CACHED_ENTITY_MANAGER_INTERFACES = new ConcurrentReferenceHashMap<>(); + private static final Map, Class[]> cachedEntityManagerInterfaces = new ConcurrentReferenceHashMap<>(4); + /** * Create an application-managed extended EntityManager proxy. @@ -226,10 +227,10 @@ public abstract class ExtendedEntityManagerCreator { boolean containerManaged, boolean synchronizedWithTransaction) { Assert.notNull(rawEm, "EntityManager must not be null"); - Class[] interfaces; + Class[] interfaces; if (emIfc != null) { - interfaces = CACHED_ENTITY_MANAGER_INTERFACES.computeIfAbsent(emIfc, key -> { + interfaces = cachedEntityManagerInterfaces.computeIfAbsent(emIfc, key -> { Set> ifcs = new LinkedHashSet<>(); ifcs.add(key); ifcs.add(EntityManagerProxy.class); @@ -237,7 +238,7 @@ public abstract class ExtendedEntityManagerCreator { }); } else { - interfaces = CACHED_ENTITY_MANAGER_INTERFACES.computeIfAbsent(rawEm.getClass(), key -> { + interfaces = cachedEntityManagerInterfaces.computeIfAbsent(rawEm.getClass(), key -> { Set> ifcs = new LinkedHashSet<>(); ifcs.addAll(ClassUtils .getAllInterfacesForClassAsSet(key, cl)); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java index 162733e3dc..8c431170a3 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java @@ -71,12 +71,12 @@ public abstract class SharedEntityManagerCreator { private static final Class[] NO_ENTITY_MANAGER_INTERFACES = new Class[0]; + private static final Map, Class[]> cachedQueryInterfaces = new ConcurrentReferenceHashMap<>(4); + private static final Set transactionRequiringMethods = new HashSet<>(8); private static final Set queryTerminatingMethods = new HashSet<>(8); - private static final Map, Class[]> CACHED_QUERY_INTERFACES = new ConcurrentReferenceHashMap<>(); - static { transactionRequiringMethods.add("joinTransaction"); transactionRequiringMethods.add("flush"); @@ -314,7 +314,7 @@ public abstract class SharedEntityManagerCreator { if (result instanceof Query) { Query query = (Query) result; if (isNewEm) { - Class[] ifcs = CACHED_QUERY_INTERFACES.computeIfAbsent(query.getClass(), key -> + Class[] ifcs = cachedQueryInterfaces.computeIfAbsent(query.getClass(), key -> ClassUtils.getAllInterfacesForClass(key, this.proxyClassLoader)); result = Proxy.newProxyInstance(this.proxyClassLoader, ifcs, new DeferredQueryInvocationHandler(query, target));