Singleton element

How do we define a service that collect stats and reports it to all users? If I define a bean in spring when I reload the page it looks like the bean is created for each user so double all of my values send to each user inside it. For example:

Say we have a class called OrderStats. This holds just numbers of total orders, total rejects etc. When we load the page with one user logged in it shows the correct stats, when we open the second browser window and login again we get the stats but they are doubled.

What’s the Scope of your stats Bean? I’m thinking @Scope(“singleton”) should be all that you need - there should be only one of those per application (or Spring IoC container to be more precise). If it’s not working correctly, then you probably have some kind of logical error in your code.

-Olli