On Fri, 7 Apr 2000, Sam Heisz wrote:
>
> What stops the instance from getting garbage collected? I read that
> starting version something-something-something, the garbage collector is
> more aggressive and will collect instances of objects that are only
> referred to by a member variable in the same class.
Do you have a reference? That would break tons of code out there,
including parts of the JDK itself that utilize the singleton pattern.
What it may have meant was if Object A is only referred to by Object B and
Object B is only referred to by Object A, they can be garbage collected --
I can see where simple implementations of a garbage collector wouldn't
be able to deal with the circular references.
The disadvantage I see with using singletons is that it does not
fulfill the requirement of having a distinct object per servlet context
when multiple servlet contexts are hosted in the same JVM. For example,
if you are virtual-hosting two separate web sites, but for resource
conservation sake want to run them both in the same java process, you may
not want them to share the same connection pool. It's almost like you
have an additional scope, "virtual machine". Another incongruity between
that and "application" scope is that an application may (if the container
allows it) be distributed/replicated over multiple virtual machines,
meaning that you're actually invoking a remote method on an RMI-extended
version of the ServletContext interface that's serializing a copy of your
application-scope object to that particular VM when required. Of
course at that level you're probably best off using a remote EJB for the
item in question.
Wes
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets