-1

We have a Spring web application, where users login in and place orders. There is a factory bean and it’s a singleton object. This factory bean holds user information. Also there will be multiple users logged into the web application at any point of time.

When I read about singleton, it says that there will be only one object created per JVM. So I want to understand how the user information will be stored in this singleton object?

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
Jose Anand
  • 35
  • 4
  • Could you share small minimal executable code, so that we are able to put our best effort to understand your problem? – Sanjeev Saha May 31 '16 at 00:39
  • In Spring, you usually don't create a class-level singleton; instead, you create a single instance of an ordinary class and let Spring take care of providing it to all the services that need it. – chrylis -cautiouslyoptimistic- May 31 '16 at 00:58
  • What is described here is not how spring defines singletons, see [Is Spring default scope Singleton or not?](https://stackoverflow.com/q/31629993/217324) – Nathan Hughes May 16 '18 at 02:55

2 Answers2

0

Given your description I deduct that the factory bean is the singleton, and that it creates user information instances. This means that all beans will use the same factory to create a user information instance; e.g. when a user logs in the factory bean is called to initiate a user.

Note: This is all theoretical since the information you shared is sparse.

uniknow
  • 938
  • 6
  • 5
0

look at this link , Singleton bean is instiate once when the Ioc container is loaded, then its property values and state are the same for all user connected if you want an object storing specific information for each user connected you have to set its scope : "session". Singleton bean may be use to store information about the sever or common to all user connected at a certain time all connected users see the same value and state for this type of bean