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