Let's imagine I have the next classes in the project based on Spring framework:
interface I {
String getName()
}
@Component
class I1 implements I {
@Override
String getName() {return "I1"}
}
@Component
class I2 implements I {
@Override
String getName() {return "I1"}
}
And I want to gather them all in the map using the @Autowired
method:
@Component
public class A {
private Map<I> map = new HashMap<>()
@Autowired
public registerI(I i) {
map.put(i.getName(), i)
}
}
Should I make this method registerI
synchronized? I mean, can Spring call this method in several threads simultaneously? Or this method will be called sequentially?
Thanks