HHH-5824 - Poor multithread performance in SessionFactoryImpl.getQueryCache method

This commit is contained in:
Steve Ebersole 2011-01-21 12:10:18 -06:00
parent 0c48de6474
commit 4d6a68c2d0
1 changed files with 22 additions and 31 deletions

View File

@ -39,6 +39,8 @@ import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
@ -179,8 +181,8 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
private final transient TransactionManager transactionManager;
private final transient QueryCache queryCache;
private final transient UpdateTimestampsCache updateTimestampsCache;
private final transient Map queryCaches;
private final transient Map allCacheRegions = new HashMap();
private final transient Map<String,QueryCache> queryCaches;
private final transient ConcurrentMap<String,Region> allCacheRegions = new ConcurrentHashMap<String, Region>();
private final transient Statistics statistics;
private final transient EventListeners eventListeners;
private final transient CurrentSessionContext currentSessionContext;
@ -401,7 +403,7 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
updateTimestampsCache = new UpdateTimestampsCache(settings, properties);
queryCache = settings.getQueryCacheFactory()
.getQueryCache(null, updateTimestampsCache, settings, properties);
queryCaches = new HashMap();
queryCaches = new HashMap<String,QueryCache>();
allCacheRegions.put( updateTimestampsCache.getRegion().getName(), updateTimestampsCache.getRegion() );
allCacheRegions.put( queryCache.getRegion().getName(), queryCache.getRegion() );
}
@ -1104,26 +1106,20 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
);
}
else {
synchronized ( allCacheRegions ) {
if ( settings.isQueryCacheEnabled() ) {
QueryCache namedQueryCache = ( QueryCache ) queryCaches.get( regionName );
if ( namedQueryCache != null ) {
namedQueryCache.clear();
// TODO : cleanup entries in queryCaches + allCacheRegions ?
}
if ( settings.isQueryCacheEnabled() ) {
QueryCache namedQueryCache = queryCaches.get( regionName );
if ( namedQueryCache != null ) {
namedQueryCache.clear();
// TODO : cleanup entries in queryCaches + allCacheRegions ?
}
}
}
}
public void evictQueryRegions() {
synchronized ( allCacheRegions ) {
Iterator regions = queryCaches.values().iterator();
while ( regions.hasNext() ) {
QueryCache cache = ( QueryCache ) regions.next();
cache.clear();
// TODO : cleanup entries in queryCaches + allCacheRegions ?
}
for ( QueryCache queryCache : queryCaches.values() ) {
queryCache.clear();
// TODO : cleanup entries in queryCaches + allCacheRegions ?
}
}
}
@ -1183,27 +1179,22 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
return null;
}
synchronized ( allCacheRegions ) {
QueryCache currentQueryCache = ( QueryCache ) queryCaches.get( regionName );
if ( currentQueryCache == null ) {
currentQueryCache = settings.getQueryCacheFactory().getQueryCache( regionName, updateTimestampsCache, settings, properties );
queryCaches.put( regionName, currentQueryCache );
allCacheRegions.put( currentQueryCache.getRegion().getName(), currentQueryCache.getRegion() );
}
return currentQueryCache;
QueryCache currentQueryCache = queryCaches.get( regionName );
if ( currentQueryCache == null ) {
currentQueryCache = settings.getQueryCacheFactory().getQueryCache( regionName, updateTimestampsCache, settings, properties );
queryCaches.put( regionName, currentQueryCache );
allCacheRegions.put( currentQueryCache.getRegion().getName(), currentQueryCache.getRegion() );
}
return currentQueryCache;
}
public Region getSecondLevelCacheRegion(String regionName) {
synchronized ( allCacheRegions ) {
return ( Region ) allCacheRegions.get( regionName );
}
return allCacheRegions.get( regionName );
}
public Map getAllSecondLevelCacheRegions() {
synchronized ( allCacheRegions ) {
return new HashMap( allCacheRegions );
}
return new HashMap( allCacheRegions );
}
public boolean isClosed() {