Article View: borland.public.jbuilder.java.language
Article #15507Re: Singleton pattern impossible in Java?
From: Steve Horsley
Date: Wed, 02 Jun 1999 00:00
Date: Wed, 02 Jun 1999 00:00
32 lines
1996 bytes
1996 bytes
I like the idea of a registry - you could just throw all the singletons into a Vector, I suppose. All you need to do is keep a "reachable" reference to your singleton somewhere. I seem to remember reading somewhere that for this very reason, the JVM 1.2 (java 2) would not dynamically unload classes any more. I don't remember where I read this. Actually, I would argue that your singleton IS reachable, and that the definition of reachable is wrong if it doesn't include such singletons (in my humble opinion). I do believe that this is normal behaviour for a 1.1 VM, though. Steve. //---------------------------------------- Thomas Moore wrote: > > Quoth Michael Boyle: > > I have been unsuccessfully attempting to implement the singleton > > pattern in my project. > [snip] > > Now, I realize that no object is storing a reference to my > > TestApp instance, but surely any static member object of a > > class should not be garbage collected. > This is a known "feature" of Java. The solution is to have a > SingletonRegistry running in a separate thread that maintains pointers > to all singletons. Mark Grand outlines this sort of thing in Patterns > in Java, Vol. 1, which I'd recommend. It's a Java-centric > implementation of the GoF patterns along with some "extras", but it goes > into some of the language specific issues you can encounter. >
Technical Details
Message-ID:
<3754F203.AC659C5B@cwcom.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<375401EA.A6FBEDCA@adopt.qc.ca> <375433B1.A731670E@celwave.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,6d4ef91dc0571b30 X-Google-Attributes: gidf74b3,public From: Steve Horsley <steve.horsley@cwcom.co.uk> Subject: Re: Singleton pattern impossible in Java? Date: 1999/06/02 Message-ID: <3754F203.AC659C5B@cwcom.co.uk> X-Deja-AN: 484793665 Content-Transfer-Encoding: 7bit References: <375401EA.A6FBEDCA@adopt.qc.ca> <375433B1.A731670E@celwave.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Cable & Wireless Communications Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language