HHH-8939 Reduce contention on initialization of ColumnNameCache instances by loaders

This commit is contained in:
Sanne Grinovero 2014-02-18 13:05:46 +00:00 committed by Brett Meyer
parent 949adc92c2
commit af5804a49c
1 changed files with 10 additions and 8 deletions

View File

@ -2104,15 +2104,17 @@ public abstract class Loader {
}
private ColumnNameCache retreiveColumnNameToIndexCache(final ResultSet rs) throws SQLException {
if ( columnNameCache == null ) {
synchronized ( this ) {
if ( columnNameCache == null ) {
LOG.trace( "Building columnName -> columnIndex cache" );
columnNameCache = new ColumnNameCache( rs.getMetaData().getColumnCount() );
}
}
final ColumnNameCache cache = columnNameCache;
if ( cache == null ) {
//there is no need for a synchronized second check, as in worst case
//we'll have allocated an unnecessary ColumnNameCache
LOG.trace( "Building columnName -> columnIndex cache" );
columnNameCache = new ColumnNameCache( rs.getMetaData().getColumnCount() );
return columnNameCache;
}
else {
return cache;
}
return columnNameCache;
}
/**