I understand that in Spring framework, the default scope of the bean is Singleton. It means that only one instance of the bean is created per the container.
But I am not able to understand practically below scenario.
For example class , let say class "SingleTonClass" is configured as singleton bean in spring context.xml,
1) for every time there is a request for this class ,does it use same instance. If yes then if I make a call like new SingleTonClass().sum(3,4)
from another class and new SingleTonClass().sum(5,6)
, will give me the results correctly or there will be a problem some times?
2) if same instance is used by all the requests, how is it possible behind the scenes that using only one instance is used by all the requests? if there are 100 requests to the same singleton class , each request has to wait until previous request is finished?
Edit:
Let say I am using @Autowired and not new operator
In my main class, I am trying to use bean configured using spring. Let say if MyMain is called multiple times(may or may not be concurrent calls), I want to understand point 2 in my post above(edit)
public class MyMain() {
@Autowired
SingleTonClass singleTonClass;
}
public class SingleTonClass {
private int a=0;
private int b=0;
public int sum(int a ,int b) {
return a+b;
}
}