Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating beans using singleton="true"?

 
selva raja
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

if I have 1 instance of the "myAccountsService","MyAccountHandler"and "geUserAccountDAOImpl" and there are many clients logged into this web-based application..is there a potential danger of requests getting mixed up and the wrong responses going back to the users?

for example, the "geUserAccountDAOImpl"is reading and writing to the db based on requests from users, say user "A" and user "B". But since there is only a single instance of "geUserAccountDAOImpl", and if "A" and "B" both call a function called "saveAccount(Account o)" or "getAccount(long id)" at the same time, will the fact that there is only one instance create any problems in the application?
If not, then what is the real use of singleton="false"?

Thanks,
selva
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on your implementation. For example, are you using instance variables that can change? Why don't you post the code with which you are concerned and someone may point out any flaws or confirm that the code is correct.
 
selva raja
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply...


I am using spring-mvc in bank application. Single day enter the 10lac users at a time access in this application. I know spring defaut is singleton. So that what is purpose of singleton="false"? When use this scenario?

Thanks,
SR
 
selva raja
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply...


I am using spring-mvc in bank application. Single day enter the 10lac users at a time access in this application. I know spring defaut is singleton. So that what is purpose of singleton="false"? When use this scenario?

Thanks,
SR
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the To singleton or not to singleton section of the documentation.
 
selva raja
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your quick reply.
Which one is best in performance wise? Singleton=”true” or Singleton=”false”.



Thanks,
selva
 
santosh dhulipala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Singleton=”true”
if we configure this in the xml it a single instance will be created by the container and whenevr we make a call it will be excuted

Singleton=”false” the other way of the above one for every request new instance is created

performance

Singleton=”true” -the requests will be waitng for the other the instance to get free
Singleton=”false” the other way



 
selva raja
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks santosh....

I understood the definition and flow of execution.

In my all service,dao, handler are in singleton.My concern is only performance wise?

Thnaks,
SR
 
santosh dhulipala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
performance depends on number of clicks at a time and rate of usage of the classes.
number of times they are called by user

i hope these classes are used only once in entire application by user

if clicks or requests are less then there will be good performance as they increase the load on the server increases and the performance will be less
 
selva raja
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic