> From: Sid Sidney [mailto:pvcsv...@yahoo.com] > Subject: Re: using static helper classes within servlets > > I was hoping to avoid this by making the delegate a static > class or maybe a singleton.
Not sure what you mean by "static class"; do you mean references to the delegate objects are stored in static fields? Whether or not you can avoid synchronization depends on exactly what's going on inside the delegate objects; are they inherently thread-safe? If not, then either separate objects or some synchronization is required. > The beanBag example is what I was attempting to do minus the > synchronized key word. On a modern JVM, the synchronized block around the retrieval of the reference will not cost much. Static initialization will of course avoid that, if it's feasible to instantiate the objects at class load time. Using the double-checked locking mechanism is still considered poor practice, since it's very easy to get wrong. The initialize-on-demand holder class is probably the best way to avoid premature object instantiation, and is guaranteed to work; this article contains the details: http://www.ibm.com/developerworks/library/j-jtp03304/ - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org