Since EJBHomeFactory is a singleton pattern, it has only one instance of the class, if I choose the 3-tier archetecture, that is, I will deploy the JSP,Servlets and EJBs in the same server, and if many servlets(for example, more than 500 clients) call the EJBHomeFactory at the same time, what will happen? All the servlets will find the EJBHomes concurrently? Or should they be in a queue to get the access to the only instance of the EJBHomeFactory class? 3x!!
The the purpose of using factory. To lookup (JNDI) the Home interface once, cache it and get it via the factory class. Any call except the first should return very quickly so it should cause problems to concurrent access.
One of the main reasons to use EJBs is to avoid any concurrency issues.
The HomeFactory needs to be written as thread-safe singleton is all (you will find lots of documentation about this on the web - try avoiding synchronization on the getHome(XXXX) and getInstance() methods).
BTW: Keep in mind, that a Singleton is not really a Singleton in J2EE (and other distributed technologies).
then, if my system is to serve hundreds of clients at once, is there any better solutions to the problem? Thanks a lot!
it only only need sync for the first time to get the home.
for the subsequence call is not needed.
so I did not see problem here to serve 500 clients.