Thamil
Thamil

Reputation: 1

Spring singleton called by two user at a time

Suppose if two users are calling spring singleton bean same time,How many instance will be created?

It is a singleton bean.Will it create two instance or one instance will be served to two request.

Upvotes: 0

Views: 80

Answers (1)

Ralph
Ralph

Reputation: 120851

There is only one instance of each Spring-Singleton-Bean at all. (It is best comparable with a CDI-Singleton-Bean).

Each Singleton-Bean is (typical) created when the application starts and gets destroyed when the application shut-down. While the application run, the same singleton bean instance get used by all "users". Even when you inject a Singleton Bean in two other Spring Beans, both will get the SAME injected bean.

So it is typical to have singleton beans effective stateless, and pass the user/request/task specific information by method arguments.

Upvotes: 1

Related Questions