Suppose there are several instances of a class simultaneously calling service methods defined in a singleton class.
Can some one explain to me what happens at the low level when a method is called in a singleton when that method is already being executed by some other instance of the class? I am thinking that JVM would block the caller until the current caller is done with the method. Is this right?
Would it improve performance if we move some of the methods in the singleton class to define them within the class needing such methods?
Would it improve performance if singleton is changed to non-singleton allowing each instance of a class needing to call the service methods in another class to create its own instance of the service class?
Assume of course singleton is stateless.
Consider the situation multiple threads calling service methods in the singleton.
Generally service objects are singleton and are stateless. So There is no impact on it. if you have multiple object instead one per class then I think it would fill the heap more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With