Subj : Re: Mono-state is thread safe? To : comp.programming.threads From : David Hopwood Date : Fri Jan 07 2005 02:34 am Min-Koo Seo wrote: > (3) > public class Mono { > > private static SomeClass c; > > static { > > try { > c = new SomeClass(...); > } > > catch(Exception e) { > throw new RuntimeException(e); > } > } > > public Mono() { > } > } > > I think (3) is thread-safe, however catch the exception in static constructor is > too messy. > > Please give a guide line of making mono-state pattern which has class as a static > field. Fix SomeClass so that its constructor can't throw checked exceptions. If you think about it, Mono is completely dependent on SomeClass and so unless the SomeClass constructor can be made robust, it's fairly pointless to try and recover in Mono. If you can't fix SomeClass, just put up with the messiness of (3). It's the simplest solution that works. -- David Hopwood .