Skip to content

Commit

Permalink
HHH-8939 Reduce contention on initialization of ColumnNameCache insta…
Browse files Browse the repository at this point in the history
…nces by loaders
  • Loading branch information
Sanne authored and brmeyer committed Feb 18, 2014
1 parent 09ea1b3 commit 0c5c980
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions hibernate-core/src/main/java/org/hibernate/loader/Loader.java
Expand Up @@ -2101,15 +2101,17 @@ private ResultSet wrapResultSetIfEnabled(final ResultSet rs, final SessionImplem
}

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;
}

/**
Expand Down

0 comments on commit 0c5c980

Please sign in to comment.