@@ -251,7 +251,6 @@ public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) {
251
251
Boolean lockFlag = isCurrentThreadAllowedToHoldSingletonLock ();
252
252
boolean acquireLock = !Boolean .FALSE .equals (lockFlag );
253
253
boolean locked = (acquireLock && this .singletonLock .tryLock ());
254
- boolean lenient = false ;
255
254
try {
256
255
Object singletonObject = this .singletonObjects .get (beanName );
257
256
if (singletonObject == null ) {
@@ -266,7 +265,6 @@ public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) {
266
265
Thread .currentThread ().getName () + "\" while other thread holds " +
267
266
"singleton lock for other beans " + this .singletonsCurrentlyInCreation );
268
267
}
269
- lenient = true ;
270
268
this .lenientCreationLock .lock ();
271
269
try {
272
270
this .singletonsInLenientCreation .add (beanName );
@@ -327,7 +325,7 @@ public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) {
327
325
// Try late locking for waiting on specific bean to be finished.
328
326
this .singletonLock .lock ();
329
327
locked = true ;
330
- // Singleton object should have appeared in the meantime.
328
+ // Lock-created singleton object should have appeared in the meantime.
331
329
singletonObject = this .singletonObjects .get (beanName );
332
330
if (singletonObject != null ) {
333
331
return singletonObject ;
@@ -341,8 +339,12 @@ public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) {
341
339
this .suppressedExceptions = new LinkedHashSet <>();
342
340
}
343
341
try {
344
- singletonObject = singletonFactory .getObject ();
345
- newSingleton = true ;
342
+ // Leniently created singleton object could have appeared in the meantime.
343
+ singletonObject = this .singletonObjects .get (beanName );
344
+ if (singletonObject == null ) {
345
+ singletonObject = singletonFactory .getObject ();
346
+ newSingleton = true ;
347
+ }
346
348
}
347
349
catch (IllegalStateException ex ) {
348
350
// Has the singleton object implicitly appeared in the meantime ->
@@ -386,15 +388,13 @@ public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) {
386
388
if (locked ) {
387
389
this .singletonLock .unlock ();
388
390
}
389
- if (lenient ) {
390
- this .lenientCreationLock .lock ();
391
- try {
392
- this .singletonsInLenientCreation .remove (beanName );
393
- this .lenientCreationFinished .signalAll ();
394
- }
395
- finally {
396
- this .lenientCreationLock .unlock ();
397
- }
391
+ this .lenientCreationLock .lock ();
392
+ try {
393
+ this .singletonsInLenientCreation .remove (beanName );
394
+ this .lenientCreationFinished .signalAll ();
395
+ }
396
+ finally {
397
+ this .lenientCreationLock .unlock ();
398
398
}
399
399
}
400
400
}
0 commit comments