17
17
package org .springframework .context .support ;
18
18
19
19
import org .junit .Test ;
20
+
20
21
import org .springframework .context .ApplicationContext ;
21
22
import org .springframework .tests .sample .beans .TestBean ;
22
23
28
29
*/
29
30
public class SimpleThreadScopeTests {
30
31
31
- private ApplicationContext applicationContext = new ClassPathXmlApplicationContext (
32
- "simpleThreadScopeTests.xml" , getClass ());
32
+ private final ApplicationContext applicationContext =
33
+ new ClassPathXmlApplicationContext ("simpleThreadScopeTests.xml" , getClass ());
34
+
33
35
34
36
@ Test
35
37
public void getFromScope () throws Exception {
@@ -45,19 +47,15 @@ public void getFromScope() throws Exception {
45
47
public void getMultipleInstances () throws Exception {
46
48
final TestBean [] beans = new TestBean [2 ];
47
49
Thread thread1 = new Thread (new Runnable () {
48
-
49
50
@ Override
50
51
public void run () {
51
- beans [0 ] = applicationContext .getBean ("threadScopedObject" ,
52
- TestBean .class );
52
+ beans [0 ] = applicationContext .getBean ("threadScopedObject" , TestBean .class );
53
53
}
54
54
});
55
55
Thread thread2 = new Thread (new Runnable () {
56
-
57
56
@ Override
58
57
public void run () {
59
- beans [1 ] = applicationContext .getBean ("threadScopedObject" ,
60
- TestBean .class );
58
+ beans [1 ] = applicationContext .getBean ("threadScopedObject" , TestBean .class );
61
59
}
62
60
});
63
61
thread1 .start ();
@@ -67,7 +65,6 @@ public void run() {
67
65
68
66
assertNotNull (beans [0 ]);
69
67
assertNotNull (beans [1 ]);
70
-
71
68
assertNotSame (beans [0 ], beans [1 ]);
72
69
}
73
70
0 commit comments