Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Daniele Futtorovic Newsgroups: comp.lang.java.gui Subject: Re: Basic program flow Date: Thu, 03 Oct 2013 07:51:41 +0200 Organization: A noiseless patient Spider Lines: 44 Message-ID: References: <1ab3peylzbmhj.1xz6jwgd30hz0.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 3 Oct 2013 05:51:47 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="b2928e61883b125ef6debc9de7bc3991"; logging-data="3821"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tN9FGGopmnXfEA7i04eMb" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 In-Reply-To: <1ab3peylzbmhj.1xz6jwgd30hz0.dlg@40tude.net> Cancel-Lock: sha1:Gj7RLJx8x0Yb3p20mLqJ3RmZmI4= Xref: csiph.com comp.lang.java.gui:5375 On 2013-10-01 12:44, Joerg Meier allegedly wrote: > On Tue, 01 Oct 2013 05:08:45 -0500, Christopher Pisz wrote: > >> What is going on, as I debug through the static main method, my window >> is created and it is displayed, and responds. Yet, the debugger steps >> out of main...Which I would think exits the program. > > AWT and Swing live on their own threads. frame.setVisible(true); starts the > AWT event thread, which continues to run after main exits, until all > visible components are disposed of. > >> Did I make a new thread when I created a frame? If so, at what point? >> Why doesn't the program exit after main is done? What keeps it alive? > > I hope all of those got answered above. Just to elaborate a bit: The runtime of the Java Virtual Machine (JVM) is based on the lifetime of threads. There are two types of threads: daemon threads and non-daemon threads ("daemon" being basically a boolean flag determined at thread creation time and before thread start time). The JVM terminates when its last active non-daemon thread terminates. Starting the JVM using the OS's executable starts a non-daemon thread that executes the designated "main" method. That threads terminates when the "main" method exits. Starting a visual component, like the AWT Frame, starts a non-daemon thread called "AWT Dispatch Thread". That thread runs until the last visual component of the specified category is disposed (to keep things simple). (What I'm trying to say is that what you are witnessing is not specific to applications with visual components, but rather a particular case of Teh Jav's general rules). HTH. -- DF.