🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19271

Re: Are there automatic threads?

#19271
From: Brian Duff
Date: Sun, 22 Feb 1998 00:00
39 lines
2340 bytes

Max Polk wrote in message ...
>Various books espouse something like this for a Java application:
>

>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?

myself is just a reference to the actual object (like a pointer, but then
Java doesn't have pointers). Using new is analogous to dynamic memory
allocation in C: you create space on the heap for that object. The actual
area of storage corresponding to your new object is accessible outside the
scope in which it was created. The *reference* to it (myself) goes out of
scope at the end of main. Java's garbage collector is clever enough to know
when the object is still in use.

>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?

yes, the reference is gone at the end of main, but the object itself isn't.

>Is there a thread magically created so that execution suspends just
>before the closing brace of the "main" method?  What's up?

AWT components are processed in a separate thread. The application doesn't
terminate until all threads terminate, so the application doesn't exit at
the end of main (the thread in which main was executed may well have
terminated, but the AWT thread hasn't).

Brian
--
When replying by e-mail, remove the _ characters from my address.
They are there for the purposes of deterring spam.
http://wiredsoc.ml.org/~briand
Technical Details
Message-ID: <6cpigg$emk3@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <MPG.f5961f423886485989690@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,f971d56aac0c447c
X-Google-Attributes: gidf74b3,public
From: "Brian Duff" <briand@____wiredsoc.ml.org>
Subject: Re: Are there automatic threads?
Date: 1998/02/22
Message-ID: <6cpigg$emk3@forums.borland.com>
X-Deja-AN: 327530738
Content-Transfer-Encoding: 7bit
References: <MPG.f5961f423886485989690@forums.borland.com>
Content-Type: text/plain; charset="iso-8859-1"
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: None
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language