@@ -139,7 +139,7 @@ public TestBean testBean1(ObjectProvider<TestBean> testBean2) {
139
139
Thread .sleep (1000 );
140
140
}
141
141
catch (InterruptedException ex ) {
142
- throw new RuntimeException ( ex );
142
+ Thread . currentThread (). interrupt ( );
143
143
}
144
144
return new TestBean ();
145
145
}
@@ -150,7 +150,7 @@ public TestBean testBean2() {
150
150
Thread .sleep (2000 );
151
151
}
152
152
catch (InterruptedException ex ) {
153
- throw new RuntimeException ( ex );
153
+ Thread . currentThread (). interrupt ( );
154
154
}
155
155
return new TestBean ();
156
156
}
@@ -170,7 +170,7 @@ public TestBean testBean1(ObjectProvider<TestBean> testBean3, ObjectProvider<Tes
170
170
Thread .sleep (1000 );
171
171
}
172
172
catch (InterruptedException ex ) {
173
- throw new RuntimeException ( ex );
173
+ Thread . currentThread (). interrupt ( );
174
174
}
175
175
return new TestBean ();
176
176
}
@@ -191,7 +191,7 @@ public TestBean testBean4() {
191
191
Thread .sleep (2000 );
192
192
}
193
193
catch (InterruptedException ex ) {
194
- throw new RuntimeException ( ex );
194
+ Thread . currentThread (). interrupt ( );
195
195
}
196
196
return new TestBean ();
197
197
}
@@ -208,7 +208,7 @@ public TestBean testBean1(ObjectProvider<TestBean> testBean2) {
208
208
Thread .sleep (1000 );
209
209
}
210
210
catch (InterruptedException ex ) {
211
- throw new RuntimeException ( ex );
211
+ Thread . currentThread (). interrupt ( );
212
212
}
213
213
return new TestBean ("testBean1" );
214
214
}
@@ -230,7 +230,7 @@ public TestBean testBean1(ObjectProvider<TestBean> testBean2) {
230
230
Thread .sleep (1000 );
231
231
}
232
232
catch (InterruptedException ex ) {
233
- throw new RuntimeException ( ex );
233
+ Thread . currentThread (). interrupt ( );
234
234
}
235
235
return new TestBean ();
236
236
}
@@ -241,7 +241,7 @@ public TestBean testBean2(TestBean testBean1) {
241
241
Thread .sleep (2000 );
242
242
}
243
243
catch (InterruptedException ex ) {
244
- throw new RuntimeException ( ex );
244
+ Thread . currentThread (). interrupt ( );
245
245
}
246
246
return new TestBean ();
247
247
}
@@ -253,37 +253,25 @@ static class CircularReferenceWithBlockingMainThreadBeanConfig {
253
253
254
254
@ Bean
255
255
public TestBean testBean1 (ObjectProvider <TestBean > testBean2 ) {
256
- Thread thread = new Thread (testBean2 ::getObject );
257
- thread .setUncaughtExceptionHandler ((t , ex ) -> System .out .println (System .currentTimeMillis () + " " + ex + " " + t ));
258
- thread .start ();
256
+ new Thread (testBean2 ::getObject ).start ();
259
257
try {
260
258
Thread .sleep (1000 );
261
259
}
262
260
catch (InterruptedException ex ) {
263
- throw new RuntimeException ( ex );
261
+ Thread . currentThread (). interrupt ( );
264
262
}
265
263
return new TestBean (testBean2 .getObject ());
266
264
}
267
265
268
266
@ Bean
269
267
public TestBean testBean2 (ObjectProvider <TestBean > testBean1 ) {
270
- System .out .println (System .currentTimeMillis () + " testBean2 begin " + Thread .currentThread ());
271
268
try {
272
269
Thread .sleep (2000 );
273
270
}
274
271
catch (InterruptedException ex ) {
275
- throw new RuntimeException (ex );
276
- }
277
- try {
278
- return new TestBean (testBean1 .getObject ());
279
- }
280
- catch (RuntimeException ex ) {
281
- System .out .println (System .currentTimeMillis () + " testBean2 exception " + Thread .currentThread ());
282
- throw ex ;
283
- }
284
- finally {
285
- System .out .println (System .currentTimeMillis () + " testBean2 end " + Thread .currentThread ());
272
+ Thread .currentThread ().interrupt ();
286
273
}
274
+ return new TestBean (testBean1 .getObject ());
287
275
}
288
276
}
289
277
@@ -298,7 +286,7 @@ public TestBean testBean1(ObjectProvider<TestBean> testBean2) {
298
286
Thread .sleep (1000 );
299
287
}
300
288
catch (InterruptedException ex ) {
301
- throw new RuntimeException ( ex );
289
+ Thread . currentThread (). interrupt ( );
302
290
}
303
291
return new TestBean ();
304
292
}
@@ -309,7 +297,7 @@ public TestBean testBean2(TestBean testBean3) {
309
297
Thread .sleep (2000 );
310
298
}
311
299
catch (InterruptedException ex ) {
312
- throw new RuntimeException ( ex );
300
+ Thread . currentThread (). interrupt ( );
313
301
}
314
302
return new TestBean ();
315
303
}
@@ -325,14 +313,17 @@ public TestBean testBean3(TestBean testBean2) {
325
313
static class CircularReferenceInMultipleThreadsBeanConfig {
326
314
327
315
@ Bean
328
- public TestBean testBean1 (ObjectProvider <TestBean > testBean2 , ObjectProvider <TestBean > testBean3 ) {
316
+ public TestBean testBean1 (ObjectProvider <TestBean > testBean2 , ObjectProvider <TestBean > testBean3 ,
317
+ ObjectProvider <TestBean > testBean4 ) {
318
+
329
319
new Thread (testBean2 ::getObject ).start ();
330
320
new Thread (testBean3 ::getObject ).start ();
321
+ new Thread (testBean4 ::getObject ).start ();
331
322
try {
332
- Thread .sleep (2000 );
323
+ Thread .sleep (3000 );
333
324
}
334
325
catch (InterruptedException ex ) {
335
- throw new RuntimeException ( ex );
326
+ Thread . currentThread (). interrupt ( );
336
327
}
337
328
return new TestBean ();
338
329
}
@@ -343,18 +334,29 @@ public TestBean testBean2(ObjectProvider<TestBean> testBean3) {
343
334
Thread .sleep (1000 );
344
335
}
345
336
catch (InterruptedException ex ) {
346
- throw new RuntimeException ( ex );
337
+ Thread . currentThread (). interrupt ( );
347
338
}
348
339
return new TestBean (testBean3 .getObject ());
349
340
}
350
341
351
342
@ Bean
352
- public TestBean testBean3 (ObjectProvider <TestBean > testBean2 ) {
343
+ public TestBean testBean3 (ObjectProvider <TestBean > testBean4 ) {
344
+ try {
345
+ Thread .sleep (1000 );
346
+ }
347
+ catch (InterruptedException ex ) {
348
+ Thread .currentThread ().interrupt ();
349
+ }
350
+ return new TestBean (testBean4 .getObject ());
351
+ }
352
+
353
+ @ Bean
354
+ public TestBean testBean4 (ObjectProvider <TestBean > testBean2 ) {
353
355
try {
354
356
Thread .sleep (1000 );
355
357
}
356
358
catch (InterruptedException ex ) {
357
- throw new RuntimeException ( ex );
359
+ Thread . currentThread (). interrupt ( );
358
360
}
359
361
return new TestBean (testBean2 .getObject ());
360
362
}
0 commit comments