Article View: borland.public.jbuilder.java.language
Article #19270Are there automatic threads?
From: Max Polk
Date: Sat, 21 Feb 1998 00:00
Date: Sat, 21 Feb 1998 00:00
30 lines
1596 bytes
1596 bytes
Various books espouse something like this for a Java application:
class Example extends Frame implements WindowListener
{
public static void main (String args[])
{
Example myself = new Example ("This is an example.");
myself.addWindowListener (myself);
myself.show ();
} // myself GOES AWAY HERE!!!!!
...
}
My question is that since main is a static method, it is called
without an object of type Example yet in existence. Therefore we
create an Example object in a local variable called "myself".
Since non-windowed applications end when you fall off the end of main,
then why doesn't "myself" go out of scope at the end of main and
become subject to possible garbage collection and object deallocation?
Note that there is no global "myself" to fix this problem and you
can't make "myself" class data since a static function can't access
class data. You are literally FORCED to use a local variable to hold
the reference to "Example." And yet it goes away when main is
finished! Is this a paradox?
Is there a thread magically created so that execution suspends just
before the closing brace of the "main" method? What's up?
Technical Details
Message-ID:
<MPG.f5961f423886485989690@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,f971d56aac0c447c,start X-Google-Attributes: gidf74b3,public From: polk@sprintmail.com (Max Polk) Subject: Are there automatic threads? Date: 1998/02/21 Message-ID: <MPG.f5961f423886485989690@forums.borland.com> X-Deja-AN: 327406652 Organization: None Newsgroups: borland.public.jbuilder.java.language