This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Performance and the fly likes Performance Issue at the worst... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Performance Issue at the worst..." Watch "Performance Issue at the worst..." New topic
Author

Performance Issue at the worst...

Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
Hello friends,
I have an application where I have used the authentication mechanism. Now in the authentication mechanism I have a class WBCredentialVerifier. I have implemented singleton pattern where I created a single object and this object is created will look up the EJB object . I have used the singleton pattern to facilitate the looking up of the object only once. Now will this be a bottle neck if more than one user is accessing the business methods of the object because this will be only a single object. This has been a performance issue.
Regards,
shekar.


Thanks,
Shekar
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Why are you using the singleton pattern? For authentication, you wouldn't be looking up the same value in the EJB each time. So it would be ok to draw from a pool of beans.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
I am using singleton pattern because the first time I create an object of that class it will look up in the constructor of the class. But the next time another uses tries to create an object of the class he need not again go to the constructor and do the lookup. this would reduce the lookups to only one. So this would be the advantage of creating a single object. But because of the creation of only one object does the following happen.
When A logs in he creates the instance of the class and looks up the EJB and he calls some methods in the same ejb. will he keep the object with him until and unless he executes all the methods.
Therefore when user B logs in just after A he cannot get the instance of the class because user A already has acquired it and until and unless the user A releases it user B cannot get it. this would be same case for 10 users. I guess this would result in low performance. Is the reasoning correct. What should be the way I should be dealing with it so that the look ups for the session bean are very less and performance is more.
any help will be of great help.
thanks and regards,
shekar.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Chandra Bairi:
When A logs in he creates the instance of the class and looks up the EJB and he calls some methods in the same ejb. will he keep the object with him until and unless he executes all the methods.
Therefore when user B logs in just after A he cannot get the instance of the class because user A already has acquired it and until and unless the user A releases it user B cannot get it. this would be same case for 10 users. I guess this would result in low performance. Is the reasoning correct.

No, you can have as many users use the object at the same time, *concurrently*, as you wish. This works without problems for stateless session beans - for statefull beans, some kind of synchronization might be necessary.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
I am using a stateless session bean. Will there be a performance problem in this case.
shekar.
Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
what will be the case if i use a java bean instead of stateless session bean.

regards,
shekar.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Ilja,
Are you limited to one user being in the session bean at a time? I thought that was the reason for pooling session beans.
Chandra,
You definitely won't have a problem with regular java beans. But then you loose the benefits of EJBs. It is still possible to do what you want without a complete singleton. You can still use a singleton/cache for the lookup and have a regular class call it. Then you could direct the user to different session beans. (which will only provide some benefit if my question to Ilja is correct)
[ March 18, 2004: Message edited by: Jeanne Boyarsky ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Jeanne Boyarsky:
Are you limited to one user being in the session bean at a time?

I would be surprised of you were - but I am far from being an EJB expert...
You definitely won't have a problem with regular java beans. But then you loose the benefits of EJBs.

Of course you would also loose its complexity. In my humble opinions, for many projects EJBs are just overkill...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Performance Issue at the worst...
 
Similar Threads
A doubt with Singleton pattern
Paramaterized Singleton Question
want to make only three objects of class
Singleton / Factory decision
Question regarding Singleton pattern