SCJP, SCMAD
Garrett Rowe wrote:Do you plan on writing any unit tests for this class?
Paul Clapham wrote:In a web application, the standard way to have only one object is to make it an attribute of the application. Which you get at via the servlet context.
Campbell Ritchie wrote:If a singleton has only private constructors, you cannot extend that class.
SCJP, SCMAD
JohnWilliam Fitz wrote:Thanks, I may do that as well. But it seems to me that alone isn't enough. It won't prevent some thread from setting the chosen attribute to null, then instantiating a brand new object (i.e. different instance) and setting the new object as the attribute. Also I need orderly startup and shutdown so that the file is open before the different threads start calling read() and write(), and so the file closed properly when the application is shutting down.
And how will you ensure that only one instance of the class can be created?Parambir Singh wrote:Yes but we can have protected constructors.
Paul wrote: but you might want to just do code reviews instead of Maginot Line programming.