Skip to content

Commit

Permalink
Fix a subtle double-checked locking issue
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanQingyangXu authored and sebersole committed Mar 19, 2020
1 parent 620dcc6 commit df0aa1e
Showing 1 changed file with 4 additions and 1 deletion.
Expand Up @@ -744,18 +744,21 @@ protected void logStaticSQL() {
}
}

private CollectionLoader standardCollectionLoader;
private volatile CollectionLoader standardCollectionLoader;

@Override
public void initialize(Object key, SharedSessionContractImplementor session) throws HibernateException {
// getAppropriateInitializer( key, session ).initialize( key, session );
determineLoaderToUse( key, session ).load( key, session );
}

// lazily initialize instance field via 'double-checked locking'
// see https://en.wikipedia.org/wiki/Double-checked_locking
protected CollectionLoader getStandardCollectionLoader() {
CollectionLoader localCopy = standardCollectionLoader;
if ( localCopy == null ) {
synchronized (this) {
localCopy = standardCollectionLoader;
if ( localCopy == null ) {
localCopy = createCollectionLoader( LoadQueryInfluencers.NONE );
standardCollectionLoader = localCopy;
Expand Down

0 comments on commit df0aa1e

Please sign in to comment.