Yes, thread safety is one, clustering issues also impact that, and transactional behavior *may* be different. Now, since the InitialContext may become stale, that means with a single IC per instance, a number of session beans will try to execute methods and fail. Those won't make it back into the pool, and will be replaced by new instances, end of story. The failover is simple.
If you share the ic among all instances of a class, then they all fail or all succeed. That means, problems may persist until the app server is restarted. These kind of problems are difficult to detect while developing/testing and are a pain in the arse to fix afterwards. Now, you DON'T want to code synchronized blocks: that's going to be worse performance wise than continous creation/destruction of an InitialContext instance. And keeping a single instance of InitialContext among all instances of a class isn't a performance optimization, but a memory-footprint optimization. Since your EJBs are going to be pooled anyway, footprint shouldn't be an issue;note that while instantiation is pretty straightforward, too, GC is one of the major performance bottlenecks in J2EE aplications. J2EE applications that reuse object instances perform better on most JVMs. Some JVMs, like JRockit, have more aggressive GC implementations that make them more suitable for intensive applications. I'm not commercially linked to JRockit. What I would do if I wanted a lessened footprint is to encapsulate the optimization with a Factory pattern, should I want to 'bail out' of using a single instance everywhere. Nevertheless, sharing an InitialContext everywhere doesn't strike me as an important optimization. Even caching it may yield marginal results depending on the JVM you deploy into. That being said, my code usually caches the InitialContext, and all the Home instances my beans use. The latter is even more dangerous if you're not in complete control of how your app is going to be deployed. 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: Eric Ma [mailto:eric.ma@;db.com] > Sent: Thursday, November 14, 2002 3:16 PM > To: Juan Pablo Lorandi > Subject: Re: InitialContext caching > > > > What is the the reason behind dedicating one InitialContext > per EJB? Are you worried about thread safety? > > Eric Ma > > > -- > > This e-mail may contain confidential and/or privileged > information. If you are not the intended recipient (or have > received this e-mail in error) please notify the sender > immediately and destroy this e-mail. Any unauthorized > copying, disclosure or distribution of the material in this > e-mail is strictly forbidden. > > > =========================================================================== 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".
