Avoid lenient locking for additional external bootstrap threads
Includes spring.locking.strict revision to differentiate between true, false, not set.
Includes checkFlag accessor on SpringProperties, also used in StatementCreatorUtils.
Closes gh-34729
See gh-34303
@ -133,6 +133,11 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -133,6 +133,11 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@ -157,8 +162,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -157,8 +162,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
/** Optional id for this factory, for serialization purposes. */
@Nullable
@ -214,6 +220,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -214,6 +220,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@ -1045,7 +1054,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -1045,7 +1054,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
}
else{
// Bean intended to be initialized in main bootstrap thread
// Bean intended to be initialized in main bootstrap thread.
thrownewBeanCurrentlyInCreationException(beanName,"Bean marked for mainline initialization "+
"but requested in background thread - enforce early instantiation in mainline thread "+
@ -1057,8 +1066,28 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -1057,8 +1066,28 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
// An unmanaged thread (assumed to be application-internal) with lenient locking,
// and not part of the same thread pool that provided the main bootstrap thread
// (excluding scenarios where we are hit by multiple external bootstrap threads).
returntrue;
}
}
// Traditional behavior: forced to always hold a full lock.
returnnull;
}
@Override
@ -1076,6 +1105,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -1076,6 +1105,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@ -1088,6 +1118,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -1088,6 +1118,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
}
finally{
this.mainThreadPrefix=null;
this.preInstantiationThread.remove();
this.preInstantiationPhase=false;
}
@ -1183,6 +1214,12 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@@ -1183,6 +1214,12 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@ -272,7 +272,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
@@ -272,7 +272,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
// Thread-safe exposure is still guaranteed, there is just a risk of collisions
// when triggering creation of other beans as dependencies of the current bean.
if(logger.isInfoEnabled()){
logger.info("Creating singleton bean '"+beanName+"' in thread \""+
logger.info("Obtaining singleton bean '"+beanName+"' in thread \""+
Thread.currentThread().getName()+"\" while other thread holds "+
"singleton lock for other beans "+this.singletonsCurrentlyInCreation);
}
@ -443,12 +443,16 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
@@ -443,12 +443,16 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements