This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Is it safe to save a JNDI InitialContext as a ServletContext attribute, and then reuse it across all servlets in a web application? Every code sample I see in my O'Reilly book on EJBs re-obtains a JNDI InitialContext in each method that needs one, as opposed to sharing it as an instance variable or as a ServletContext attribute. Thanks in advance. ------------------ Miftah Khan - Sun Certified Programmer for the Java� 2 Platform - Sun Certified Web Component Developer for the Java� 2 Platform, Enterprise Edition
Yes, there is a risk. The JNDI Context is not defined by the spec as being threadsafe, which leaves it up to the vendor's discretion. In fact, many implementions of JNDI do not provide threadsafe InitialContext objects. So, the O'Reilly books are following a best practice. Don't cache InitialContexts, and get a new one every time you need one. Kyle ------------------ Kyle Brown, Author of Enterprise Java (tm) Programming with IBM Websphere See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
Thank you. I was hoping you'd write back. ------------------ Miftah Khan - Sun Certified Programmer for the Java� 2 Platform - Sun Certified Web Component Developer for the Java� 2 Platform, Enterprise Edition