From 0f0a95e2b86180db910902862468a4358764e1c4 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Tue, 18 Feb 2014 13:05:46 +0000 Subject: [PATCH] HHH-8939 Reduce contention on initialization of ColumnNameCache instances by loaders --- .../main/java/org/hibernate/loader/Loader.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java index 2ac3bfc7bb..5a2642fb51 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java @@ -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; } /**