The main reason behind the existence of the Singleton pattern itself is to conceal(encapsulate) from the application the number of instances that exist to provide "global" functionality. It allows to refactor a Singleton into a full class without modifying existing code. This discussion has already taken place elsewhere, so I'll get right down to my humble opinion: yes, you should use a singleton instead of static methods in a utility class, especially when using a distributed computing platform such as J2EE. Singleton will work every time just as well as the static utility class, and won't compromise any future migration. There's no difference in effort needed to implement either choice. Problems with either choice are the usual when using custom classloaders and a distributed computing platform, but since the goal is to cache EJBHome instances, these problems can be ignored(the cache may not be as efficient as it could be, but big performance gains will be there anyway).
Also bear in mind that such EJBHome cache may not work seamlessly in all containers, since many may enroll the EJBHome instance in a particular transaction, which will in turn make the instance useless in any other transaction. An EJBHome is a fully blown transactional component that executes business rules(altough they may not be coded in Java but in SQL or EQL), and it may attempt to vote within the current transaction to no avail. Storing handles to EJBHome instances may work better, but with performance losses. My 2c, Juan Pablo Lorandi Chief Software Architect Code Foundry Ltd. [EMAIL PROTECTED] Barberstown, Straffan, Co. Kildare, Ireland. Tel: +353-1-6012050 Fax: +353-1-6012051 Mobile: +353-86-2157900 www.codefoundry.com > -----Original Message----- > From: A mailing list for Enterprise JavaBeans development > [mailto:[EMAIL PROTECTED]] On Behalf Of David M. Karr > Sent: Tuesday, July 30, 2002 4:39 PM > To: [EMAIL PROTECTED] > Subject: Effect of "static" EJBHomeFactory vs. "singleton" > > > This is really a general question about issues between using > the standard "singleton" pattern, versus a "static utility" > class, in the context of the EJB environment. > > In particular, is there a problem with designing an > EJBHomeFactory class which consists of just static > synchronized methods, as opposed to just having a static > "getInstance()" method and a private static "EJBHomeFactory" instance? > > -- =================================================================== > David M. Karr ; Java/J2EE/XML/Unix/C++ > [EMAIL PROTECTED] > > ============================================================== > ============= > To unsubscribe, send email to [EMAIL PROTECTED] and > include in the body of the message "signoff EJB-INTEREST". > For general help, send email to [EMAIL PROTECTED] and > include in the body of the message "help". > =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
