> From: Christopher Schultz [mailto:ch...@christopherschultz.net] > Subject: Re: using static helper classes within servlets > > You can get a significant performance improvement by doing this > instead: > > private static final SomeBean someBean = new SomeBean(); > > public static getSomeBean() { > return someBean; > } > > Of course, if you're going for delayed/lazy instantiation, you're not > going to get it, but you at least drop the penalty for synchronization.
Using an initialize-on-demand holder class permits lazy instantiation: class MyClass { ... private static class LazySomethingHolder { public static final Something something = new Something(); } ... public static Something getInstance() { return LazySomethingHolder.something; } ... } The LazySomethingHolder will be loaded - but not initialized - when MyClass is loaded. Initialization will occur only when MyClass.getInstance() is invoked. The necessary synchronization during initialization is all handled internally by the JVM. - 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.