[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5824) Poor multithread performance in SessionFactoryImpl.getQueryCache method

Alexey Romanchuk (JIRA) noreply at atlassian.com
Fri Jan 7 00:12:05 EST 2011


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

                 Key: HHH-5824
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5824
             Project: Hibernate Core
          Issue Type: Bug
          Components: caching (L2)
    Affects Versions: 3.6.0
            Reporter: Alexey Romanchuk


Synchronize all access to Map is multithreading bottleneck. ConcurrentHashMap or write syncronization can solve this issue.
Here it is how SessionFactoryImpl.getQueryCache can be implemented:
{code}
public QueryCache getQueryCache(String regionName) throws HibernateException {
		if ( regionName == null ) {
			return getQueryCache();
		}

		if ( !settings.isQueryCacheEnabled() ) {
			return null;
		}

		QueryCache currentQueryCache = ( QueryCache ) queryCaches.get( regionName );
	    if ( currentQueryCache == null ) {
    		synchronized ( allCacheRegions ) {
    			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;
	}
{code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list