File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Creating beans using singleton= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Creating beans using singleton="true"?" Watch "Creating beans using singleton="true"?" New topic
Author

Creating beans using singleton="true"?

selva raja
Ranch Hand

Joined: Nov 24, 2009
Posts: 69
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

Joined: Jun 01, 2010
Posts: 618
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

Joined: Nov 24, 2009
Posts: 69
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

Joined: Nov 24, 2009
Posts: 69
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

Joined: Jun 01, 2010
Posts: 618
See the To singleton or not to singleton section of the documentation.
selva raja
Ranch Hand

Joined: Nov 24, 2009
Posts: 69
Thanks for your quick reply.
Which one is best in performance wise? Singleton=”true” or Singleton=”false”.



Thanks,
selva
santosh dhulipala
Ranch Hand

Joined: Oct 21, 2010
Posts: 52
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




Thanks & Regards
Santosh Kumar.D

selva raja
Ranch Hand

Joined: Nov 24, 2009
Posts: 69
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

Joined: Oct 21, 2010
Posts: 52
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

Joined: Nov 24, 2009
Posts: 69
Thanks..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating beans using singleton="true"?